diff options
author | Rubén Dávila Santos <ruben@gitlab.com> | 2016-08-20 00:01:49 +0000 |
---|---|---|
committer | Ruben Davila <rdavila84@gmail.com> | 2016-08-19 19:04:01 -0500 |
commit | 3c27937ffc906177f082a8db0791f6ad566bb719 (patch) | |
tree | 6a4d203a70ce35161103cb32ae32e2527499fd3f | |
parent | 4bb1db901c83b885a8dca8234bab5055f0293a06 (diff) | |
download | gitlab-ce-3c27937ffc906177f082a8db0791f6ad566bb719.tar.gz |
Merge branch 'fix-diff-note-discussion-id' into 'master'
Call `set_discussion_id` again in DiffNote `before_validation` because the order is important
See merge request !5913
-rw-r--r-- | app/models/diff_note.rb | 3 | ||||
-rw-r--r-- | db/migrate/20160819221631_add_index_to_note_discussion_id.rb | 14 | ||||
-rw-r--r-- | db/migrate/20160819221833_reset_diff_note_discussion_id_because_it_was_calculated_wrongly.rb | 12 | ||||
-rw-r--r-- | db/schema.rb | 3 |
4 files changed, 31 insertions, 1 deletions
diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb index aa54189fea9..c8320ff87fa 100644 --- a/app/models/diff_note.rb +++ b/app/models/diff_note.rb @@ -16,6 +16,9 @@ class DiffNote < Note after_initialize :ensure_original_discussion_id before_validation :set_original_position, :update_position, on: :create before_validation :set_line_code, :set_original_discussion_id + # We need to do this again, because it's already in `Note`, but is affected by + # `update_position` and needs to run after that. + before_validation :set_discussion_id after_save :keep_around_commits class << self diff --git a/db/migrate/20160819221631_add_index_to_note_discussion_id.rb b/db/migrate/20160819221631_add_index_to_note_discussion_id.rb new file mode 100644 index 00000000000..b6e8bb18e7b --- /dev/null +++ b/db/migrate/20160819221631_add_index_to_note_discussion_id.rb @@ -0,0 +1,14 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddIndexToNoteDiscussionId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def change + add_concurrent_index :notes, :discussion_id + end +end diff --git a/db/migrate/20160819221833_reset_diff_note_discussion_id_because_it_was_calculated_wrongly.rb b/db/migrate/20160819221833_reset_diff_note_discussion_id_because_it_was_calculated_wrongly.rb new file mode 100644 index 00000000000..0c68cf01900 --- /dev/null +++ b/db/migrate/20160819221833_reset_diff_note_discussion_id_because_it_was_calculated_wrongly.rb @@ -0,0 +1,12 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class ResetDiffNoteDiscussionIdBecauseItWasCalculatedWrongly < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + execute "UPDATE notes SET discussion_id = NULL WHERE discussion_id IS NOT NULL AND type = 'DiffNote'" + end +end diff --git a/db/schema.rb b/db/schema.rb index 040573da848..6cbc766831b 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: 20160818205718) do +ActiveRecord::Schema.define(version: 20160819221833) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -702,6 +702,7 @@ ActiveRecord::Schema.define(version: 20160818205718) do add_index "notes", ["author_id"], name: "index_notes_on_author_id", using: :btree add_index "notes", ["commit_id"], name: "index_notes_on_commit_id", using: :btree add_index "notes", ["created_at"], name: "index_notes_on_created_at", using: :btree + add_index "notes", ["discussion_id"], name: "index_notes_on_discussion_id", using: :btree add_index "notes", ["line_code"], name: "index_notes_on_line_code", using: :btree add_index "notes", ["note"], name: "index_notes_on_note_trigram", using: :gin, opclasses: {"note"=>"gin_trgm_ops"} add_index "notes", ["noteable_id", "noteable_type"], name: "index_notes_on_noteable_id_and_noteable_type", using: :btree |