Skip to content

Commit

Permalink
Establish sync_enum_values TableReference order
Browse files Browse the repository at this point in the history
  • Loading branch information
artem.golovin committed Jun 29, 2024
1 parent 1c9e4f8 commit 8a7cf99
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def sync_changed_enums(
enum_name,
list(old_values),
list(new_values),
list(affected_columns),
sorted(
affected_columns,
key=lambda reference: (reference.table_schema, reference.table_name, reference.column_name),
),
)
upgrade_ops.ops.append(op)
4 changes: 2 additions & 2 deletions tests/sync_enum_values/test_run_array_new_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_expected_upgrade(self) -> str:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('a', sa.Column('value', postgresql.ARRAY(postgresql.ENUM('A', 'B', 'C', name='my_enum', create_type=False)), server_default=sa.text("ARRAY['A', 'B']::my_enum[]"), nullable=True))
op.sync_enum_values('public', 'my_enum', ['A', 'B', 'C'],
[TableReference(table_schema='public', table_name='b', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A'::my_enum, 'B'::my_enum]"), TableReference(table_schema='public', table_name='a', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A', 'B']::my_enum[]")],
[TableReference(table_schema='public', table_name='a', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A', 'B']::my_enum[]"), TableReference(table_schema='public', table_name='b', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A'::my_enum, 'B'::my_enum]")],
enum_values_to_rename=[])
# ### end Alembic commands ###
"""
Expand All @@ -73,7 +73,7 @@ def get_expected_downgrade(self) -> str:
return """
# ### commands auto generated by Alembic - please adjust! ###
op.sync_enum_values('public', 'my_enum', ['A', 'B'],
[TableReference(table_schema='public', table_name='b', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A'::my_enum, 'B'::my_enum]"), TableReference(table_schema='public', table_name='a', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A', 'B']::my_enum[]")],
[TableReference(table_schema='public', table_name='a', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A', 'B']::my_enum[]"), TableReference(table_schema='public', table_name='b', column_name='value', column_type=ColumnType.ARRAY, existing_server_default="ARRAY['A'::my_enum, 'B'::my_enum]")],
enum_values_to_rename=[])
op.drop_column('a', 'value')
# ### end Alembic commands ###
Expand Down

0 comments on commit 8a7cf99

Please sign in to comment.