Fix role enum migration constraint handling#35
Merged
chrystianmartins merged 1 commit intoFeb 9, 2026
Conversation
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.
Motivation
0003_update_user_role_enum_for_new_auth_flowAlembic migration was failing on some Postgres databases because the check constraint backing the non-nativeEnum(..., native_enum=False)column did not have the expected name, causingpsycopg.errors.UndefinedObjectduringDROP CONSTRAINT.Description
rolecolumn toVARCHAR(32)explicitly before remapping values in bothupgrade()anddowngrade()usingALTER TABLE users ALTER COLUMN role TYPE VARCHAR(32) USING role::text.DROP CONSTRAINT IF EXISTScalls for common generated names (role_enum,ck_users_role_enum,users_role_check) and then add an explicitCHECKconstraint for the target values before converting back to theEnumtype.batch_op.alter_columncalls to useexisting_type=sa.String(length=32)while converting to/from thesa.Enumtypes to match the intermediate string column state.pool-coordinator/alembic/versions/0003_update_user_role_enum_for_new_auth_flow.pyand affect bothupgrade()anddowngrade()flows.Testing
python -m compileall pool-coordinator/alembic/versions/0003_update_user_role_enum_for_new_auth_flow.pyand the compilation succeeded.Codex Task