Skip to content

fix: use postgresql.ENUM in migrations to honor create_type=False#11

Merged
jeanpaulsio merged 1 commit intomainfrom
fix/alembic-enum-create-type
Apr 13, 2026
Merged

fix: use postgresql.ENUM in migrations to honor create_type=False#11
jeanpaulsio merged 1 commit intomainfrom
fix/alembic-enum-create-type

Conversation

@jeanpaulsio
Copy link
Copy Markdown
Owner

Summary

  • sa.Enum(..., create_type=False) does not reliably forward the flag to the postgres dialect when SQLAlchemy adapts the generic type. SQLAlchemy still emits CREATE TYPE at op.create_table time, so on a fresh DB ensure_enum_exists creates user_role / token_type / item_status and then the table create fails with psycopg2.errors.DuplicateObject: type "user_role" already exists.
  • Switch the two seed migrations (0001_initial_schema, 0002_create_items_table) to postgresql.ENUM(..., create_type=False), which actually honors the flag.
  • Update app/db/migration_helpers.py docstring and CLAUDE.md so future migrations copy the correct pattern.

Test plan

  • cd server && alembic upgrade head against a fresh Postgres — should create enums + tables without DuplicateObject.
  • alembic downgrade base && alembic upgrade head cycle — should still work (idempotent enum create + explicit drop).
  • ruff check, ruff format --check, mypy app/ — all pass locally.

🤖 Generated with Claude Code

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>
@jeanpaulsio jeanpaulsio merged commit 0f74757 into main Apr 13, 2026
3 checks passed
@jeanpaulsio jeanpaulsio deleted the fix/alembic-enum-create-type branch April 13, 2026 19:15
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