Running more than one migration on same table
seban opened this issue · 2 comments
Currently I am investigating one issues I had with my app. Let consider the migation like ⬇️
class MyMigration < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
add_index :some_big_table, [:column_a, :column_b], algorithm: :concurrently
remove_index :some_big_table, :column_a, algorithm: :concurrently
end
end
At first glance everything is fine as this is concurrently
, but under the hood Postgres locks the table with share update exclusive to prevent simultaneous schema changes. Wouldn't it be good if online_migrations warn about such behaviour and advice? Is it aligned with vision for this tool?
Which problem are you facing?
Rails does not support concurrent schema changes and from logical point, this should never be done. So this migration locks the table 2 times, allowing concurrent crud operations on data (https://www.postgresql.org/docs/current/explicit-locking.html).
There is no way postgres can add/remove indexes better than running concurrently
, so I do not think we should warn the user. Every operation requires some kind of the lock.
Closing this. Feel free to provide more details.