fix: use postgresql.ENUM in migrations to honor create_type=False#11
Merged
jeanpaulsio merged 1 commit intomainfrom Apr 13, 2026
Merged
fix: use postgresql.ENUM in migrations to honor create_type=False#11jeanpaulsio merged 1 commit intomainfrom
jeanpaulsio merged 1 commit intomainfrom
Conversation
sa.Enum(..., create_type=False) does not reliably forward the flag to the postgres dialect when adapting, so SQLAlchemy still emits CREATE TYPE at op.create_table time. On a fresh DB, ensure_enum_exists creates the type and then the table create fails with DuplicateObject. Switch both seed migrations (and the helper/CLAUDE.md docs) to postgresql.ENUM, which actually honors create_type=False. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
sa.Enum(..., create_type=False)does not reliably forward the flag to the postgres dialect when SQLAlchemy adapts the generic type. SQLAlchemy still emitsCREATE TYPEatop.create_tabletime, so on a fresh DBensure_enum_existscreatesuser_role/token_type/item_statusand then the table create fails withpsycopg2.errors.DuplicateObject: type "user_role" already exists.0001_initial_schema,0002_create_items_table) topostgresql.ENUM(..., create_type=False), which actually honors the flag.app/db/migration_helpers.pydocstring andCLAUDE.mdso future migrations copy the correct pattern.Test plan
cd server && alembic upgrade headagainst a fresh Postgres — should create enums + tables withoutDuplicateObject.alembic downgrade base && alembic upgrade headcycle — should still work (idempotent enum create + explicit drop).ruff check,ruff format --check,mypy app/— all pass locally.🤖 Generated with Claude Code