From db7493e67b1394f985370c9b265f8908f87bf43e Mon Sep 17 00:00:00 2001 From: "artem.golovin" Date: Sun, 31 Mar 2024 21:33:29 +0400 Subject: [PATCH] Ignore dialects other than postgresql --- alembic_postgresql_enum/compare_dispatch.py | 10 ++++++++++ alembic_postgresql_enum/operations/sync_enum_values.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/alembic_postgresql_enum/compare_dispatch.py b/alembic_postgresql_enum/compare_dispatch.py index a61a90f..f1a86ec 100644 --- a/alembic_postgresql_enum/compare_dispatch.py +++ b/alembic_postgresql_enum/compare_dispatch.py @@ -1,3 +1,4 @@ +import logging from typing import Iterable, Union import alembic @@ -16,6 +17,9 @@ from alembic_postgresql_enum.get_enum_data import get_defined_enums, get_declared_enums +log = logging.getLogger(f"alembic.{__name__}") + + @alembic.autogenerate.comparators.dispatch_for("schema") def compare_enums( autogen_context: AutogenContext, @@ -28,6 +32,12 @@ def compare_enums( for each defined enum that has changed new entries when compared to its declared version. """ + if autogen_context.dialect.name != "postgresql": + log.warning( + f"This library only supports postgresql, but you are using {autogen_context.dialect.name}, skipping" + ) + return + add_create_type_false(upgrade_ops) add_postgres_using_to_text(upgrade_ops) diff --git a/alembic_postgresql_enum/operations/sync_enum_values.py b/alembic_postgresql_enum/operations/sync_enum_values.py index 896d53c..714fe9f 100644 --- a/alembic_postgresql_enum/operations/sync_enum_values.py +++ b/alembic_postgresql_enum/operations/sync_enum_values.py @@ -1,3 +1,4 @@ +import logging from typing import List, Tuple, Any, Iterable, TYPE_CHECKING import alembic.autogenerate @@ -31,6 +32,9 @@ from alembic_postgresql_enum.get_enum_data import TableReference, ColumnType +log = logging.getLogger(f"alembic.{__name__}") + + @alembic.operations.base.Operations.register_operation("sync_enum_values") class SyncEnumValuesOp(alembic.operations.ops.MigrateOperation): operation_name = "change_enum_variants" @@ -138,6 +142,12 @@ def sync_enum_values( ] If there was server default with old_name it will be renamed accordingly """ + if operations.migration_context.dialect.name != "postgresql": + log.warning( + f"This library only supports postgresql, but you are using {operations.migration_context.dialect.name}, skipping" + ) + return + enum_values_to_rename = list(enum_values_to_rename) with get_connection(operations) as connection: