Skip to content

Fix role enum migration constraint handling#35

Merged
chrystianmartins merged 1 commit into
mainfrom
codex/fix-database-migration-issue-with-role_enum
Feb 9, 2026
Merged

Fix role enum migration constraint handling#35
chrystianmartins merged 1 commit into
mainfrom
codex/fix-database-migration-issue-with-role_enum

Conversation

@chrystianmartins

Copy link
Copy Markdown
Owner

Motivation

  • The 0003_update_user_role_enum_for_new_auth_flow Alembic migration was failing on some Postgres databases because the check constraint backing the non-native Enum(..., native_enum=False) column did not have the expected name, causing psycopg.errors.UndefinedObject during DROP CONSTRAINT.

Description

  • Convert the role column to VARCHAR(32) explicitly before remapping values in both upgrade() and downgrade() using ALTER TABLE users ALTER COLUMN role TYPE VARCHAR(32) USING role::text.
  • Perform defensive DROP CONSTRAINT IF EXISTS calls for common generated names (role_enum, ck_users_role_enum, users_role_check) and then add an explicit CHECK constraint for the target values before converting back to the Enum type.
  • Adjust batch_op.alter_column calls to use existing_type=sa.String(length=32) while converting to/from the sa.Enum types to match the intermediate string column state.
  • Changes are in pool-coordinator/alembic/versions/0003_update_user_role_enum_for_new_auth_flow.py and affect both upgrade() and downgrade() flows.

Testing

  • Compiled the updated migration file with python -m compileall pool-coordinator/alembic/versions/0003_update_user_role_enum_for_new_auth_flow.py and the compilation succeeded.

Codex Task

@chrystianmartins
chrystianmartins merged commit bf2026c into main Feb 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant