Commit fdcafe72 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'zj-rework-migration-award-emoji' into 'master'

Fix timing issues on convertion migration award emoji

See merge request !4581
parents 4b964011 c6744b49
# rubocop:disable all # rubocop:disable all
class ConvertAwardNoteToEmojiAward < ActiveRecord::Migration class ConvertAwardNoteToEmojiAward < ActiveRecord::Migration
def change disable_ddl_transaction!
def up 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)" 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" execute "DELETE FROM notes WHERE is_award = true"
remove_column :notes, :is_award, :boolean
end
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
end end
# rubocop:disable all
class RemoveNoteIsAward < ActiveRecord::Migration
def change
remove_column :notes, :is_award, :boolean
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment