summaryrefslogtreecommitdiff
path: root/alembic/ddl
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-01-27 14:01:40 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-01-28 13:46:37 -0500
commit407316635cdb8edf95f8ee7bd06a5f2dd01eda26 (patch)
treea91ba3d82c1482ea440150d6868d79acaae0b82f /alembic/ddl
parent3d0ab3ddda45564a7f3bbd65c810242b9e673845 (diff)
downloadalembic-407316635cdb8edf95f8ee7bd06a5f2dd01eda26.tar.gz
Enable SQL Server testing and fix autogen issues
Fixed assorted autogenerate issues with SQL Server: * ignore default reflected identity on primary_key columns * improve server default comparison Updated test_autogen_fks for modern levels of FK capabilities Change-Id: I94b815cedf90422ccd5ceceb765b07d772b505b7 Fixes: #787
Diffstat (limited to 'alembic/ddl')
-rw-r--r--alembic/ddl/impl.py10
-rw-r--r--alembic/ddl/mssql.py36
-rw-r--r--alembic/ddl/postgresql.py2
3 files changed, 46 insertions, 2 deletions
diff --git a/alembic/ddl/impl.py b/alembic/ddl/impl.py
index 923fd8b..62692d2 100644
--- a/alembic/ddl/impl.py
+++ b/alembic/ddl/impl.py
@@ -555,7 +555,15 @@ class DefaultImpl(with_metaclass(ImplMeta)):
diff.difference_update(self.identity_attrs_ignore)
- return diff, ignored
+ # returns 3 values:
+ return (
+ # different identity attributes
+ diff,
+ # ignored identity attributes
+ ignored,
+ # if the two identity should be considered different
+ bool(diff) or bool(metadata_identity) != bool(inspector_identity),
+ )
def _compare_identity_options(
diff --git a/alembic/ddl/mssql.py b/alembic/ddl/mssql.py
index 916011a..18e09f8 100644
--- a/alembic/ddl/mssql.py
+++ b/alembic/ddl/mssql.py
@@ -178,6 +178,42 @@ class MSSQLImpl(DefaultImpl):
table_name, column, schema=schema, **kw
)
+ def compare_server_default(
+ self,
+ inspector_column,
+ metadata_column,
+ rendered_metadata_default,
+ rendered_inspector_default,
+ ):
+ def clean(value):
+ if value is not None:
+ value = value.strip()
+ while value[0] == "(" and value[-1] == ")":
+ value = value[1:-1]
+ return value
+
+ return clean(rendered_inspector_default) != clean(
+ rendered_metadata_default
+ )
+
+ def _compare_identity_default(self, metadata_identity, inspector_identity):
+ diff, ignored, is_alter = super(
+ MSSQLImpl, self
+ )._compare_identity_default(metadata_identity, inspector_identity)
+
+ if (
+ metadata_identity is None
+ and inspector_identity is not None
+ and not diff
+ and inspector_identity.column is not None
+ and inspector_identity.column.primary_key
+ ):
+ # mssql reflect primary keys with autoincrement as identity
+ # columns. if no different attributes are present ignore them
+ is_alter = False
+
+ return diff, ignored, is_alter
+
class _ExecDropConstraint(Executable, ClauseElement):
def __init__(self, tname, colname, type_, schema):
diff --git a/alembic/ddl/postgresql.py b/alembic/ddl/postgresql.py
index b8fdd99..6a2f007 100644
--- a/alembic/ddl/postgresql.py
+++ b/alembic/ddl/postgresql.py
@@ -319,7 +319,7 @@ def visit_identity_column(element, compiler, **kw):
return text
else:
# alter identity
- diff, _ = element.impl._compare_identity_default(
+ diff, _, _ = element.impl._compare_identity_default(
element.default, element.existing_server_default
)
identity = element.default