Skip to content

fix(migrate): don't keep a migration that failed its test - #172

Open
cultron wants to merge 1 commit into
mainfrom
fix/migrate-discard-failed
Open

cultron wants to merge 1 commit into
mainfrom
fix/migrate-discard-failed

Conversation

@cultron

@cultron cultron commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

apso migrate writes the migration, then tests it on a PGlite copy of the deployed schema. When the test failed, the migration stayed on disk, so the next run read it as deployed and printed "Nothing to migrate". The error message told people to rerun, which then did nothing.

Now a failed test deletes the migration and its .plan.json and restores .apso/migration-plan.json with the answers and baseline. Rerunning, either with a changed answer or with --accept-loss when the loss is intended, picks up where it stopped.

Checked end to end on a scaffolded TypeScript project with the split-field fixture:

  1. apso migrate --baseline deployed.apsorc --answer field:Contact.fullName=drop --seed seed.sql fails on data loss (contact.fullName: 4 of 4 values), exits 1, and leaves no migration file. The plan keeps both answers and before.
  2. apso migrate --seed seed.sql --accept-loss contact.fullName writes the migration and verifies it, exit 0.

tsc clean, lint 0 errors, 518 tests pass.

apso migrate wrote the migration, then tested it. On a failure the file
stayed, so the next run read it as the deployed schema and reported
nothing to migrate. Now a failed test deletes the migration and its
.plan.json and restores .apso/migration-plan.json, which keeps the answers
and the baseline. A rerun (with a changed answer, or --accept-loss when
the loss is intended) picks up where the failed one stopped.

Checked end to end on a scaffolded TS project: dropping Contact.fullName
with seeded rows fails on data loss and leaves no migration; rerunning
with --accept-loss contact.fullName writes and verifies it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant