summaryrefslogtreecommitdiff
path: root/tests/test_postgresql.py
diff options
context:
space:
mode:
authorJan Katins <jasc@gmx.net>2023-03-06 16:18:17 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2023-03-06 19:25:59 -0500
commit6f8d9af59aa431aca3be851066c729c52b12a7a2 (patch)
tree444b0d5bf76c9788cc42b084661bc3df04ff52da /tests/test_postgresql.py
parentcd7b1a94cc90ca533a84b47332900888151e22d0 (diff)
downloadalembic-6f8d9af59aa431aca3be851066c729c52b12a7a2.tar.gz
improve autogen rendering for PG ExcludeConstraint
Fixed issue regarding PostgreSQL :class:`.ExcludeConstraint`, where constraint elements which made use of :func:`.literal_column` could not be rendered for autogenerate. Additionally, using SQLAlchemy 2.0.5 or greater, :func:`.text()` constructs are also supported within PostgreSQL :class:`.ExcludeConstraint` objects for autogenerate render. Pull request courtesy Jan Katins. Fixes: #1184 Closes: #1185 Pull-request: https://github.com/sqlalchemy/alembic/pull/1185 Pull-request-sha: 68360ce9aa746a85407c5e1e04b8021123d98504 Change-Id: I302f3f4007a186ffac13b344ff6769dd302f28f5
Diffstat (limited to 'tests/test_postgresql.py')
-rw-r--r--tests/test_postgresql.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py
index a8c284d..18f50ce 100644
--- a/tests/test_postgresql.py
+++ b/tests/test_postgresql.py
@@ -28,6 +28,7 @@ from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.sql import column
from sqlalchemy.sql import false
from sqlalchemy.sql import table
+from sqlalchemy.sql.expression import literal_column
from alembic import autogenerate
from alembic import command
@@ -1156,6 +1157,64 @@ class PostgresqlAutogenRenderTest(TestBase):
"name='TExclX'))",
)
+ def test_inline_exclude_constraint_literal_column(self):
+ """test for #1184"""
+
+ autogen_context = self.autogen_context
+
+ m = MetaData()
+ t = Table(
+ "TTable",
+ m,
+ Column("id", String()),
+ ExcludeConstraint(
+ (literal_column("id + 2"), "="), name="TExclID", using="gist"
+ ),
+ )
+
+ op_obj = ops.CreateTableOp.from_table(t)
+
+ eq_ignore_whitespace(
+ autogenerate.render_op_text(autogen_context, op_obj),
+ "op.create_table('TTable',sa.Column('id', sa.String(), "
+ "nullable=True),"
+ "postgresql.ExcludeConstraint((sa.literal_column('id + 2'), '='), "
+ "using='gist', "
+ "name='TExclID'))",
+ )
+
+ @config.requirements.sqlalchemy_2
+ def test_inline_exclude_constraint_text(self):
+ """test for #1184.
+
+ Requires SQLAlchemy 2.0.5 due to issue
+ https://github.com/sqlalchemy/sqlalchemy/issues/9401
+
+ """
+
+ autogen_context = self.autogen_context
+
+ m = MetaData()
+ t = Table(
+ "TTable",
+ m,
+ Column("id", String()),
+ ExcludeConstraint(
+ (text("id + 2"), "="), name="TExclID", using="gist"
+ ),
+ )
+
+ op_obj = ops.CreateTableOp.from_table(t)
+
+ eq_ignore_whitespace(
+ autogenerate.render_op_text(autogen_context, op_obj),
+ "op.create_table('TTable',sa.Column('id', sa.String(), "
+ "nullable=True),"
+ "postgresql.ExcludeConstraint((sa.text('id + 2'), '='), "
+ "using='gist', "
+ "name='TExclID'))",
+ )
+
def test_json_type(self):
eq_ignore_whitespace(
autogenerate.render._repr_type(JSON(), self.autogen_context),