Keep fresh database migrations idempotent - #782
Merged
Conversation
The initial revision builds the current ORM schema on empty databases, so the logical-deletion revision must tolerate its columns and indexes already existing. Inspect each object independently and add a migration-only empty-database CI stage so this path fails before full application startup. Constraint: The dynamic initial_schema baseline remains unchanged in this hotfix. Rejected: Rewrite the historical baseline here | requires a full migration-chain schema audit and would broaden an urgent deployment fix. Confidence: high Scope-risk: narrow Reversibility: clean Directive: Keep new schema revisions compatible with fresh metadata creation until initial_schema is replaced by a static baseline. Tested: 12 scoped pytest tests; Ruff on changed Python; shell syntax; Compose config; YAML parsing; git diff check. Not-tested: Local PostgreSQL container run because the Docker daemon is unavailable; the new Drone stage provides this verification.
The upgrade job selects v1.11.2 as its source, but that released image cannot bootstrap an empty database because it contains the duplicate-column migration. Build its schema through the parent revision, apply the corrected head with the target image, then continue the existing old-app and target-app upgrade assertions. Constraint: v1.11.2 is the latest release tag and is itself unable to initialize the CI source database. Rejected: Skip the upgrade job or ignore its failure | would leave the PR red and remove existing-database coverage. Confidence: high Scope-risk: narrow Reversibility: clean Directive: Remove the v1.11.2 bootstrap compatibility path after it is no longer a supported upgrade source. Tested: POSIX shell syntax; 12 scoped pytest tests; git diff check. Not-tested: Local Docker execution because the Docker daemon is unavailable; Drone exercises this exact path.
Y1fe1Zh0u
marked this pull request as ready for review
July 24, 2026 04:05
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.
Root cause
The initial_schema revision creates tables from current ORM metadata on a fresh database. The logical-deletion models already contain the deleted_at columns and active partial indexes, but add_agent_model_deleted_at attempted to create the same objects unconditionally. Fresh deployments therefore failed with PostgreSQL DuplicateColumnError before application startup.
What changed
Impact
Fresh installations can reach the current Alembic head even though the initial revision has already materialized the current logical-deletion schema. Existing databases still receive any missing columns or indexes during normal upgrades.
Validation
The successful upgrade reached add_agent_model_deleted_at head and LangGraph checkpoint version 9 while preserving the database and workspace sentinels.
Follow-up scope
This hotfix does not rewrite initial_schema or change dependency resolution:
Those stability improvements require broader audits and are intentionally separated from the deployment-blocking fix.