Skip to content

A platform for community discussion. Free, open, simple.

DEV: Safeguard for migration that disables DDL transactions.

Guo Xiang Tanf40b28d4c7e0
diff --git a/db/migrate/20190409054736_add_index_for_rebake_old_on_posts.rb b/db/migrate/20190409054736_add_index_for_rebake_old_on_posts.rb
index 74c79805f3f..05746115e5c 100644
--- a/db/migrate/20190409054736_add_index_for_rebake_old_on_posts.rb
+++ b/db/migrate/20190409054736_add_index_for_rebake_old_on_posts.rb
@@ -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