diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-14 12:52:17 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-14 12:52:17 +0000 |
commit | fdcafe72d1e103821ecad075dec82a84ad24387b (patch) | |
tree | 5b1dff1774d7ec1bccfc9235ed798a568cdc4d73 | |
parent | 4b964011cfd6861403726248574f5926edc5d495 (diff) | |
parent | c6744b49497fca340c8ee5b9913f805ec8ea9be8 (diff) | |
download | gitlab-ce-fdcafe72d1e103821ecad075dec82a84ad24387b.tar.gz |
Merge branch 'zj-rework-migration-award-emoji' into 'master'
Fix timing issues on convertion migration award emoji
See merge request !4581
-rw-r--r-- | db/migrate/20160416182152_convert_award_note_to_emoji_award.rb | 33 | ||||
-rw-r--r-- | db/migrate/20160416190505_remove_note_is_award.rb | 6 |
2 files changed, 30 insertions, 9 deletions
diff --git a/db/migrate/20160416182152_convert_award_note_to_emoji_award.rb b/db/migrate/20160416182152_convert_award_note_to_emoji_award.rb index c226bc11f6c..95ee03611d9 100644 --- a/db/migrate/20160416182152_convert_award_note_to_emoji_award.rb +++ b/db/migrate/20160416182152_convert_award_note_to_emoji_award.rb @@ -1,10 +1,37 @@ # rubocop:disable all class ConvertAwardNoteToEmojiAward < ActiveRecord::Migration - def change - def up - execute "INSERT INTO award_emoji (awardable_type, awardable_id, user_id, name, created_at, updated_at) (SELECT noteable_type, noteable_id, author_id, note, created_at, updated_at FROM notes WHERE is_award = true)" + disable_ddl_transaction! + + def up + if Gitlab::Database.postgresql? + migrate_postgresql + else + migrate_mysql + end + end + + def down + add_column :notes, :is_award, :boolean + # This migration does NOT move the awards on notes, if the table is dropped in another migration, these notes will be lost. + execute "INSERT INTO notes (noteable_type, noteable_id, author_id, note, created_at, updated_at, is_award) (SELECT awardable_type, awardable_id, user_id, name, created_at, updated_at, TRUE FROM award_emoji)" + end + + def migrate_postgresql + connection.transaction do + execute 'LOCK notes IN EXCLUSIVE MODE' + execute "INSERT INTO award_emoji (awardable_type, awardable_id, user_id, name, created_at, updated_at) (SELECT noteable_type, noteable_id, author_id, note, created_at, updated_at FROM notes WHERE is_award = true)" execute "DELETE FROM notes WHERE is_award = true" + remove_column :notes, :is_award, :boolean end end + + def migrate_mysql + execute 'LOCK TABLES notes WRITE, award_emoji WRITE;' + execute 'INSERT INTO award_emoji (awardable_type, awardable_id, user_id, name, created_at, updated_at) (SELECT noteable_type, noteable_id, author_id, note, created_at, updated_at FROM notes WHERE is_award = true);' + execute "DELETE FROM notes WHERE is_award = true" + remove_column :notes, :is_award, :boolean + ensure + execute 'UNLOCK TABLES' + end end diff --git a/db/migrate/20160416190505_remove_note_is_award.rb b/db/migrate/20160416190505_remove_note_is_award.rb deleted file mode 100644 index dd24917feb9..00000000000 --- a/db/migrate/20160416190505_remove_note_is_award.rb +++ /dev/null @@ -1,6 +0,0 @@ -# rubocop:disable all -class RemoveNoteIsAward < ActiveRecord::Migration - def change - remove_column :notes, :is_award, :boolean - end -end |