ORM-12: Support rebuilds_tables migrations (foreign-key-safe) #12
Labels
No labels
area:core
area:database
area:migrations
area:model
area:relations
area:schema
area:tests
breaking-change
size:M
size:S
tracking
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
NoctisWolfshadow/tessera-orm#12
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Depends on: #11
Context
SQLite's
ALTER TABLEcannot change constraints (addNOT NULL, change a foreign key, and so on). The supported route is create-new / copy / drop / rename, which needsPRAGMA foreign_keys = OFFoutside the transaction, because the pragma is a no-op inside one. Skipping this either fails the migration or silently cascades deletes through child tables.Tasks
.rebuilds_tables(): read the currentforeign_keysvalue, switch it off, begin, runup, runPRAGMA foreign_key_check, record, commit, then restore the previous value on every path including errors.foreign_key_checkreturns rows, roll back withMigrationError::ForeignKeyViolation.run()and #13 share.Example
Sequence the runner executes:
Acceptance criteria
ForeignKeyViolation.foreign_keysis back to its previous value after success and after failure.Migrator::rollback(steps)#13