fix(migrations): make f061 idempotent so fresh deployments can migrate - #848
Open
libingtong wants to merge 1 commit into
Open
fix(migrations): make f061 idempotent so fresh deployments can migrate#848libingtong wants to merge 1 commit into
libingtong wants to merge 1 commit into
Conversation
001_initial_schema.py builds the schema with Base.metadata.create_all(), so a
freshly provisioned database already has enterprise_info.tenant_id — the model
declares it. f061 then calls op.add_column() unconditionally and fails:
asyncpg.exceptions.DuplicateColumnError:
column "tenant_id" of relation "enterprise_info" already exists
`alembic upgrade head` therefore cannot complete on any fresh deployment, and
backend/entrypoint.sh aborts before starting uvicorn (it runs migrations first).
Reproduce against an empty database:
docker run -d --name pg -e POSTGRES_USER=clawith -e POSTGRES_PASSWORD=clawith \
-e POSTGRES_DB=clawith -p 5432:5432 postgres:15-alpine
cd backend
DATABASE_URL=postgresql+asyncpg://clawith:clawith@127.0.0.1:5432/clawith \
alembic upgrade head
Guard the DDL with IF NOT EXISTS / IF EXISTS, matching the convention already
used in 010_column_modify.py. This also makes the module docstring's stated
"Idempotence: Safe for retry" property actually hold.
Existing deployments that predate the column are unaffected — the column is
still created there. Verified both paths: fresh database, and an existing
database at allow_checkpoint_deliveries upgrading through f060 to f061.
Drops two imports that are no longer referenced.
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.
001_initial_schema.pybuilds the schema withBase.metadata.create_all(), so a freshly provisioned database already hasenterprise_info.tenant_id— the model declares it.f061then callsop.add_column()unconditionally and fails:alembic upgrade headtherefore cannot complete on any fresh deployment, andbackend/entrypoint.shaborts before starting uvicorn since it runs migrations first.Reproduction
Against an empty database, on a clean checkout of
main:docker run -d --name pg -e POSTGRES_USER=clawith -e POSTGRES_PASSWORD=clawith \ -e POSTGRES_DB=clawith -p 5432:5432 postgres:15-alpine cd backend DATABASE_URL=postgresql+asyncpg://clawith:clawith@127.0.0.1:5432/clawith \ alembic upgrade headThis PR
Guards the DDL with
IF NOT EXISTS/IF EXISTS, matching the convention already used throughout010_column_modify.py. This also makes the module docstring's stated "Idempotence: Safe for retry" property actually hold.Existing deployments that predate the column are unaffected — the column is still created there.
Verified
Both paths tested:
alembic upgrade headnow completesallow_checkpoint_deliveries→ upgrades throughf060tof061with data intactAlso drops two imports that are no longer referenced.