diff options
author | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-06-10 17:33:23 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-14 12:19:38 +0200 |
commit | fc5b3a8fa51a4cbc116cc7e702602dd03cb726e1 (patch) | |
tree | 937e66de291c42b304f12b6c30da81419542499d /db | |
parent | f8290c2862c04f9f4cd4973824ea732ef7f6871b (diff) | |
download | gitlab-ce-fc5b3a8fa51a4cbc116cc7e702602dd03cb726e1.tar.gz |
Fix MySQL migration, obtain lock the right way
As suggested by @yorrickpeterse in
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4581#note_12373882
the locking of the MySQL database wasn't correct.
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20160416182152_convert_award_note_to_emoji_award.rb | 17 |
1 files changed, 9 insertions, 8 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 b523f17417a..3906ab79398 100644 --- a/db/migrate/20160416182152_convert_award_note_to_emoji_award.rb +++ b/db/migrate/20160416182152_convert_award_note_to_emoji_award.rb @@ -20,20 +20,21 @@ class ConvertAwardNoteToEmojiAward < ActiveRecord::Migration def migrate_postgresql connection.transaction do execute 'LOCK notes IN EXCLUSIVE' - migrate_notes + 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' - migrate_notes - ensure - execute 'UNLOCK TABLES' - end + execute <<-EOF + lock tables notes WRITE, award_emoji WRITE; + 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); + EOF - def migrate_notes - 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 |