strong_migrations: Support custom checks against the TableDefinition object in the `create_table` block
Hi! There’s currently a check against adding foreign key constraints unsafely. This problem is that this doesn’t include adding foreign keys using the create_table method, e.g.:
create_table(:menus) do |t|
t.references :restaurant, null: false, foreign_key: true, type: :uuid
end
This circumvents the check, which can cause locking and downtime. Some options in the solution space here:
- Have the foreign key check include looking at the TableDefinition object passed into
create_tablefor foreign key additions - More generally, allow strong_migrations users to configure custom checks against the TableDefinition
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (9 by maintainers)
I don’t know the exact differences but our teams understanding is the same as @bullfight’s. That Postgres can lock the referenced tables so it’s not safe.
Here’s an example migration that brought our db to a halt.
Adding / validating the foreign keys across separately did not.
Just one example, so not conclusive. But we’re now enforcing adding foreign keys separately because we’ve been bitten more than once by this. Keen to hear if you know what else could be the issue with the first migration.