Implement deferred schema cleanup when applying multiple migrations#1025
Open
blakewatters wants to merge 3 commits intoxataio:mainfrom
Open
Implement deferred schema cleanup when applying multiple migrations#1025blakewatters wants to merge 3 commits intoxataio:mainfrom
blakewatters wants to merge 3 commits intoxataio:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
pgroll migrateapplies multiple outstanding migrations, it breaks zero-downtime guarantees by dropping the previous version schema during each intermediateComplete()call. If an application is still connected via that schema, its queries break immediately.Example: App runs on
public_v1. Migrations v2, v3, v4 are pending:public_v2public_v1(app breaks here!)public_v2public_v4This PR implements deferred schema cleanup so that intermediate
Complete()calls skip theDROP SCHEMAstep, and a batch cleanup runs after all migrations finish — dropping only the intermediate schemas while preserving the original (app-connected) and latest versions.Changes
pkg/roll/execute.go: AddedCompleteOptionfunctional option type withWithSkipSchemaDrop()to makeComplete()conditionally skip dropping the previous version schema. AddedDropVersionSchemasExcept()method to drop all version schemas except a specified keep list.cmd/start.go: ThreadedCompleteOptionthroughrunMigration()so callers can forward options toComplete().cmd/migrate.go: Updated batch orchestration to record the original version before the batch, passWithSkipSchemaDrop()for intermediate migrations, and callDropVersionSchemasExcept()after the batch to clean up intermediates while preserving the original and latest schemas.pkg/roll/execute_test.go: Added four integration tests covering skip-drop behavior, full multi-migration batch flow with cleanup, the cleanup method itself, and unchanged single-migration behavior.Behavior after this change
Complete()drops the previous schemastart/completeWithSkipSchemaDrop()is never passedmigrateTest plan
go test ./...)TestCompleteWithSkipSchemaDropPreservesPreviousVersionSchema— verifiesWithSkipSchemaDropprevents schema dropTestMultiMigrationBatchPreservesOriginalSchema— end-to-end batch flow: original schema persists through intermediates, cleanup drops only intermediatesTestDropVersionSchemasExceptKeepsSpecifiedSchemas— cleanup method keeps specified schemas and drops the restTestSingleMigrationCompleteStillDropsPreviousSchema— normal single-migration behavior is unchangedpgroll migrate ./migrations, verify original schema persists until cleanup🤖 Generated with Claude Code