diff --git a/app/models/concerns/ignorable_column.rb b/app/models/concerns/ignorable_column.rb new file mode 100644 index 00000000000..eb9f3423e48 --- /dev/null +++ b/app/models/concerns/ignorable_column.rb @@ -0,0 +1,28 @@ +# Module that can be included into a model to make it easier to ignore database +# columns. +# +# Example: +# +# class User < ActiveRecord::Base +# include IgnorableColumn +# +# ignore_column :updated_at +# end +# +module IgnorableColumn + extend ActiveSupport::Concern + + module ClassMethods + def columns + super.reject { |column| ignored_columns.include?(column.name) } + end + + def ignored_columns + @ignored_columns ||= Set.new + end + + def ignore_column(name) + ignored_columns << name.to_s + end + end +end diff --git a/app/models/note.rb b/app/models/note.rb index 6cb9e84ce26..49ba4ad3f2e 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -9,6 +9,9 @@ class Note < ActiveRecord::Base include CacheMarkdownField include AfterCommitQueue include ResolvableNote + include IgnorableColumn + + ignore_column :original_discussion_id cache_markdown_field :note, pipeline: :note diff --git a/db/post_migrate/20170404170532_remove_notes_original_discussion_id.rb b/db/post_migrate/20170404170532_remove_notes_original_discussion_id.rb new file mode 100644 index 00000000000..0c3b3bd5eb3 --- /dev/null +++ b/db/post_migrate/20170404170532_remove_notes_original_discussion_id.rb @@ -0,0 +1,23 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveNotesOriginalDiscussionId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + # When using the methods "add_concurrent_index" or "add_column_with_default" + # you must disable the use of transactions as these methods can not run in an + # existing transaction. When using "add_concurrent_index" make sure that this + # method is the _only_ method called in the migration, any other changes + # should go in a separate migration. This ensures that upon failure _only_ the + # index creation fails and can be retried or reverted easily. + # + # To disable transactions uncomment the following line and remove these + # comments: + # disable_ddl_transaction! + + def change + remove_column :notes, :original_discussion_id, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index af7dc07d5ba..ce65ddaccc9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170402231018) do +ActiveRecord::Schema.define(version: 20170404170532) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -724,7 +724,6 @@ ActiveRecord::Schema.define(version: 20170402231018) do t.datetime "resolved_at" t.integer "resolved_by_id" t.string "discussion_id" - t.string "original_discussion_id" t.text "note_html" end