From d5a18a6c55bf6c427536c185d66e339766843100 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 13 Jun 2016 14:15:11 +0200 Subject: Move LOCK TABLES to a separate execute MySQL apparently doesn't support executing multiple queries in the same `execute` call so we have to use a separate one for the "LOCK TABLES" statement. --- db/migrate/20160416182152_convert_award_note_to_emoji_award.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 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 13b47713137..822e7a3eff4 100644 --- a/db/migrate/20160416182152_convert_award_note_to_emoji_award.rb +++ b/db/migrate/20160416182152_convert_award_note_to_emoji_award.rb @@ -26,11 +26,8 @@ class ConvertAwardNoteToEmojiAward < ActiveRecord::Migration end def migrate_mysql - 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 - + 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 -- cgit v1.2.1