diff --git a/clickhouse_sqlalchemy/alembic/comparators.py b/clickhouse_sqlalchemy/alembic/comparators.py index e2f73209..5e9f8b08 100644 --- a/clickhouse_sqlalchemy/alembic/comparators.py +++ b/clickhouse_sqlalchemy/alembic/comparators.py @@ -1,9 +1,10 @@ import logging +from alembic import __version__ as alembic_version from alembic.autogenerate import comparators from alembic.autogenerate.compare import _compare_columns from alembic.operations.ops import ModifyTableOps -from alembic.util.sqla_compat import _reflect_table +from alembic.util.sqla_compat import _reflect_table as _alembic_reflect_table from sqlalchemy import schema as sa_schema from sqlalchemy import text @@ -12,6 +13,10 @@ logger = logging.getLogger(__name__) +alembic_version = tuple( + (int(x) if x.isdigit() else x) for x in alembic_version.split('.') +) + def _extract_to_table_name(create_table_query): query = create_table_query @@ -29,6 +34,13 @@ def _extract_to_table_name(create_table_query): comparators.dispatch_for('schema', 'clickhouse')(default_comparator) +def _reflect_table(inspector, table): + if alembic_version >= (1, 11, 0): + return _alembic_reflect_table(inspector, table) + else: + return _alembic_reflect_table(inspector, table) + + @comparators.dispatch_for('schema', 'clickhouse') def compare_mat_view(autogen_context, upgrade_ops, schemas): connection = autogen_context.connection