Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating enum values in non-default schema fails #34

Closed
anujm08 opened this issue Oct 11, 2023 · 0 comments · Fixed by #35
Closed

Updating enum values in non-default schema fails #34

anujm08 opened this issue Oct 11, 2023 · 0 comments · Fixed by #35
Assignees
Labels
bug Something isn't working

Comments

@anujm08
Copy link

anujm08 commented Oct 11, 2023

On adding values to an enum type in non-default schema. The generated upgrade migration is the following:

def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.sync_enum_values('schema_abc', 'enum_abc', ['VALUE_1', 'VALUE_2', 'VALUE_3'],
                        [('table_1', 'col_1')],
                        enum_values_to_rename=[])
    # ### end Alembic commands ###

The code at sync_enum_values tries to do the following step:

  • Renames the existing type to enum_abc_old.
  • Create a new type enum_abc with updated values and some functions/operators
  • Alter the impacted tables to use the new enum_type
  • Drop old type enum_abc_old

However, the last step fails the schema is not specified and hence enum is not found in the default public schema.

The fix for this could be to update the following lines in enum_alteration.py

connection.execute(sqlalchemy.text(
            f"""DROP TYPE {temporary_enum_name};"""
        ))

to

connection.execute(sqlalchemy.text(
            f"""DROP TYPE {schema}.{temporary_enum_name};"""
        ))
@RustyGuard RustyGuard added the bug Something isn't working label Oct 12, 2023
@RustyGuard RustyGuard self-assigned this Oct 12, 2023
RustyGuard added a commit that referenced this issue Oct 12, 2023
@RustyGuard RustyGuard linked a pull request Oct 12, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants