DEV: Safeguard for migration that disables DDL transactions.

Follow up to c82a9290250f39e67acfed429e3888781447f720.
This commit is contained in:
Guo Xiang Tan 2019-04-09 14:12:57 +08:00
parent 55d62471a5
commit f40b28d4c7

View File

@ -2,21 +2,20 @@ class AddIndexForRebakeOldOnPosts < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
def up
remove_index :posts, name: :index_posts_on_id_and_baked_version
if index_exists?(:posts, :index_posts_on_id_and_baked_version)
remove_index :posts, name: :index_posts_on_id_and_baked_version
end
add_index :posts, :id,
order: { id: :desc },
where: "(baked_version IS NULL OR baked_version < 2) AND deleted_at IS NULL",
name: :index_for_rebake_old,
algorithm: :concurrently
if !index_exists?(:posts, :index_for_rebake_old)
add_index :posts, :id,
order: { id: :desc },
where: "(baked_version IS NULL OR baked_version < 2) AND deleted_at IS NULL",
name: :index_for_rebake_old,
algorithm: :concurrently
end
end
def down
remove_index :posts, name: :index_for_rebake_old
add_index :posts, [:id, :baked_version],
order: { id: :desc },
where: "(deleted_at IS NULL)",
algorithm: :concurrently
raise ActiveRecord::IrreversibleMigration
end
end