summaryrefslogtreecommitdiff
path: root/alembic
diff options
context:
space:
mode:
authorCaselIT <cfederico87@gmail.com>2022-07-04 22:47:20 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2022-07-14 11:55:52 -0400
commitba8e22b2e29abcbfeac8a25e289191da0e7217c3 (patch)
treeb41752b53c23887a968f2fbc3f0f7eafe93c3ee3 /alembic
parent03e4f51196d175d2e04fdc633822ca70704c7149 (diff)
downloadalembic-ba8e22b2e29abcbfeac8a25e289191da0e7217c3.tar.gz
Ignore reflected expression based indexes
this establishes forwads-compatibility for PostgreSQL expression-based index reflection being added in I3e36d557235286c0f7f6d8276272ff9225058d48 Change-Id: I81d7832f254f50dc3417dd3437c2b49ec3a549e2
Diffstat (limited to 'alembic')
-rw-r--r--alembic/autogenerate/compare.py24
-rw-r--r--alembic/ddl/postgresql.py8
-rw-r--r--alembic/testing/requirements.py5
3 files changed, 29 insertions, 8 deletions
diff --git a/alembic/autogenerate/compare.py b/alembic/autogenerate/compare.py
index 693efae..5b69815 100644
--- a/alembic/autogenerate/compare.py
+++ b/alembic/autogenerate/compare.py
@@ -279,12 +279,22 @@ def _compare_tables(
upgrade_ops.ops.append(modify_table_ops)
-def _make_index(params: Dict[str, Any], conn_table: "Table") -> "Index":
+def _make_index(
+ params: Dict[str, Any], conn_table: "Table"
+) -> Optional["Index"]:
+ exprs = []
+ for col_name in params["column_names"]:
+ if col_name is None:
+ util.warn(
+ "Skipping reflected expression-based "
+ f"index {params['name']!r}"
+ )
+ return None
+ else:
+ item = conn_table.c[col_name]
+ exprs.append(item)
ix = sa_schema.Index(
- params["name"],
- *[conn_table.c[cname] for cname in params["column_names"]],
- unique=params["unique"],
- _table=conn_table,
+ params["name"], *exprs, unique=params["unique"], _table=conn_table
)
if "duplicates_constraint" in params:
ix.info["duplicates_constraint"] = params["duplicates_constraint"]
@@ -585,7 +595,9 @@ def _compare_indexes_and_uniques(
)
conn_indexes = set( # type:ignore[assignment]
- _make_index(ix, conn_table) for ix in conn_indexes
+ index
+ for index in (_make_index(ix, conn_table) for ix in conn_indexes)
+ if index is not None
)
# 2a. if the dialect dupes unique indexes as unique constraints
diff --git a/alembic/ddl/postgresql.py b/alembic/ddl/postgresql.py
index 019eb3c..5d93803 100644
--- a/alembic/ddl/postgresql.py
+++ b/alembic/ddl/postgresql.py
@@ -249,9 +249,13 @@ class PostgresqlImpl(DefaultImpl):
while isinstance(expr, UnaryExpression):
expr = expr.element
if not isinstance(expr, Column):
+ if sqla_compat.sqla_2:
+ msg = ""
+ else:
+ msg = "; not supported by SQLAlchemy reflection"
util.warn(
- "autogenerate skipping functional index %s; "
- "not supported by SQLAlchemy reflection" % idx.name
+ "autogenerate skipping functional index "
+ f"{idx.name!r}{msg}"
)
metadata_indexes.discard(idx)
diff --git a/alembic/testing/requirements.py b/alembic/testing/requirements.py
index 3947272..6896276 100644
--- a/alembic/testing/requirements.py
+++ b/alembic/testing/requirements.py
@@ -20,6 +20,11 @@ class SuiteRequirements(Requirements):
return exclusions.closed()
@property
+ def materialized_views(self):
+ """needed for sqlalchemy compat"""
+ return exclusions.closed()
+
+ @property
def unique_constraint_reflection(self):
def doesnt_have_check_uq_constraints(config):
from sqlalchemy import inspect