Remove and ignore notes.original_discussion_id column

This commit is contained in:
Douwe Maan 2017-04-04 17:41:04 -05:00 committed by Luke "Jared" Bennett
parent c319f21141
commit 63c7801e45
No known key found for this signature in database
GPG key ID: 402ED51FB5D306C2
4 changed files with 55 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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