diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2023-03-07 01:11:33 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2023-03-07 01:11:33 +0000 |
commit | 370d14b131bf6f595097e37e88f13cf52604c2f4 (patch) | |
tree | e092d05792a55bc786a21e50a01faa4903b5f451 /tests | |
parent | 3cf19f16631e54108e5f519348cba14521b7433e (diff) | |
parent | 6f8d9af59aa431aca3be851066c729c52b12a7a2 (diff) | |
download | alembic-370d14b131bf6f595097e37e88f13cf52604c2f4.tar.gz |
Merge "improve autogen rendering for PG ExcludeConstraint" into main
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_postgresql.py | 59 |
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), |