diff options
author | Jesse Bakker <github@jessebakker.com> | 2022-09-06 16:00:10 -0400 |
---|---|---|
committer | mike bayer <mike_mp@zzzcomputing.com> | 2022-10-04 02:40:20 +0000 |
commit | b6eed88ef4ebb3fd7035b4e366bf6653ebb26d15 (patch) | |
tree | e98e19d6fa7b236cf2fc7eed3ffc96c805b80667 /test/sql/test_constraints.py | |
parent | d5905ccd7df000143194975f8f3d72fcef0672e3 (diff) | |
download | sqlalchemy-b6eed88ef4ebb3fd7035b4e366bf6653ebb26d15.tar.gz |
Make if_exists and if_not_exists flags on ddl statements match compiler
Added ``if_exists`` and ``if_not_exists`` parameters for all "Create" /
"Drop" constructs including :class:`.CreateSequence`,
:class:`.DropSequence`, :class:`.CreateIndex`, :class:`.DropIndex`, etc.
allowing generic "IF EXISTS" / "IF NOT EXISTS" phrases to be rendered
within DDL. Pull request courtesy Jesse Bakker.
Fixes: #7354
Closes: #8492
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8492
Pull-request-sha: d107c6ce553bd430111607815f5b3938ffc4770c
Change-Id: I367e57b2d9216f5180bcc44e86ca6f3dc794e5ca
Diffstat (limited to 'test/sql/test_constraints.py')
-rw-r--r-- | test/sql/test_constraints.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/sql/test_constraints.py b/test/sql/test_constraints.py index 462667bed..b1b731d66 100644 --- a/test/sql/test_constraints.py +++ b/test/sql/test_constraints.py @@ -765,6 +765,14 @@ class ConstraintCompilationTest(fixtures.TestBase, AssertsCompiledSQL): i = Index("xyz", t.c.x) self.assert_compile(schema.CreateIndex(i), "CREATE INDEX xyz ON t (x)") + def test_create_index_if_not_exists(self): + t = Table("t", MetaData(), Column("x", Integer)) + i = Index("xyz", t.c.x) + self.assert_compile( + schema.CreateIndex(i, if_not_exists=True), + "CREATE INDEX IF NOT EXISTS xyz ON t (x)", + ) + def test_drop_index_plain_unattached(self): self.assert_compile( schema.DropIndex(Index(name="xyz")), "DROP INDEX xyz" @@ -775,6 +783,12 @@ class ConstraintCompilationTest(fixtures.TestBase, AssertsCompiledSQL): schema.DropIndex(Index(name="xyz")), "DROP INDEX xyz" ) + def test_drop_index_if_exists(self): + self.assert_compile( + schema.DropIndex(Index(name="xyz"), if_exists=True), + "DROP INDEX IF EXISTS xyz", + ) + def test_create_index_schema(self): t = Table("t", MetaData(), Column("x", Integer), schema="foo") i = Index("xyz", t.c.x) |