From 4df1f8393d4f44e74f82d35cf7237b28632a7745 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 26 Sep 2022 22:31:05 -0400 Subject: [PATCH] add "index", "unique" to Column.merge() attrs Fixes: #8578 Change-Id: Ic79c19748d5bb00353d0a97f3a4b4f5eb9fdbb0c --- lib/sqlalchemy/sql/schema.py | 6 ++++++ test/orm/declarative/test_typed_mapping.py | 2 ++ test/sql/test_metadata.py | 2 ++ 3 files changed, 10 insertions(+) diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 5655371098..bbf78e6a1c 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2327,6 +2327,12 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause[_T]): new_onupdate = self.onupdate._copy() new_onupdate._set_parent(other) + if self.index and not other.index: + other.index = True + + if self.unique and not other.unique: + other.unique = True + for const in self.constraints: if not const._type_bound: new_const = const._copy() diff --git a/test/orm/declarative/test_typed_mapping.py b/test/orm/declarative/test_typed_mapping.py index 16cfee3407..99c57e6ebe 100644 --- a/test/orm/declarative/test_typed_mapping.py +++ b/test/orm/declarative/test_typed_mapping.py @@ -666,6 +666,8 @@ class MappedColumnTest(fixtures.TestBase, testing.AssertsCompiledSQL): ("nullable", True), ("nullable", False), ("type", BigInteger()), + ("index", True), + ("unique", True), argnames="paramname, value", ) @testing.combinations(True, False, argnames="optional") diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 7131476be2..38255f9775 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -4198,6 +4198,8 @@ class ColumnDefinitionTest(AssertsCompiledSQL, fixtures.TestBase): ("server_default", func.foo()), ("nullable", True), ("nullable", False), + ("index", True), + ("unique", True), ("type", BigInteger()), ("type", Enum("one", "two", "three", create_constraint=True)), argnames="paramname, value", -- 2.47.2