diff --git a/alembic_postgresql_enum/detection_of_changes/enum_alteration.py b/alembic_postgresql_enum/detection_of_changes/enum_alteration.py index bc5c7ca..52cca2a 100644 --- a/alembic_postgresql_enum/detection_of_changes/enum_alteration.py +++ b/alembic_postgresql_enum/detection_of_changes/enum_alteration.py @@ -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) diff --git a/tests/sync_enum_values/test_run_array_new_column.py b/tests/sync_enum_values/test_run_array_new_column.py index da2f671..26d5451 100644 --- a/tests/sync_enum_values/test_run_array_new_column.py +++ b/tests/sync_enum_values/test_run_array_new_column.py @@ -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 ### """ @@ -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 ###