You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add_reference creates the column, then the index, then the foreign key. Since disable_ddl_transaction! is recommended when trying to add a reference with a concurrent index, the table can put into a partially migrated state with no automatic way to rollback since transactions were disabled.
Would add the column city_id on users and then attempt to create the index. This indexing operation could fail due to a reason such as ActiveRecord::LockWaitTimeout: PG::LockNotAvailable: ERROR: canceling statement due to lock timeout. The column will remain even though the index failed since transactions are disabled. Re-running the migration will fail since Rails does not expect city_id on users to already exist.
I suggest that the recommendation for adding a reference with a concurrent index for Postgres is changed to this:
Howdy,
I think section for adding-a-reference could be improved. For Postgres, it can cause a broken migration, as I have just recently found out.
The problem is that add_reference is a multi-step operation.
add_reference
creates the column, then the index, then the foreign key. Sincedisable_ddl_transaction!
is recommended when trying to add a reference with a concurrent index, the table can put into a partially migrated state with no automatic way to rollback since transactions were disabled.For example,
Would add the column
city_id
onusers
and then attempt to create the index. This indexing operation could fail due to a reason such asActiveRecord::LockWaitTimeout: PG::LockNotAvailable: ERROR: canceling statement due to lock timeout
. The column will remain even though the index failed since transactions are disabled. Re-running the migration will fail since Rails does not expectcity_id
onusers
to already exist.I suggest that the recommendation for adding a reference with a concurrent index for Postgres is changed to this:
This way the index creation can be re-attempted separate from the column creation. Safe migration.
The text was updated successfully, but these errors were encountered: