Skip to content

Commit

Permalink
Ignore dialects other than postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
artem.golovin committed Mar 31, 2024
1 parent 69e75e3 commit 5e14549
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions alembic_postgresql_enum/compare_dispatch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Iterable, Union

import alembic
Expand All @@ -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,
Expand All @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions alembic_postgresql_enum/operations/sync_enum_values.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import List, Tuple, Any, Iterable, TYPE_CHECKING

import alembic.autogenerate
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 5e14549

Please sign in to comment.