summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2020-12-14 16:35:56 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2020-12-14 16:35:56 +0000
commitaa47eca615eaf8277f6a6365a05539fda1b725e2 (patch)
tree28567a48673024bd80473ff0a62f3f82a4ccc2f3 /test/sql
parent8d3254b6727b306e19dd0db299586b95caa46c9e (diff)
parent0d50b0c7c5b0a9fda4c962f09900e45bebeb1a02 (diff)
downloadsqlalchemy-aa47eca615eaf8277f6a6365a05539fda1b725e2.tar.gz
Merge "Support IF EXISTS/IF NOT EXISTS for DDL constructs"
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_compiler.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 75ac896e9..fdffe04bf 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -31,6 +31,7 @@ from sqlalchemy import exists
from sqlalchemy import Float
from sqlalchemy import ForeignKey
from sqlalchemy import func
+from sqlalchemy import Index
from sqlalchemy import Integer
from sqlalchemy import intersect
from sqlalchemy import join
@@ -4471,6 +4472,40 @@ class DDLTest(fixtures.TestBase, AssertsCompiledSQL):
"PRIMARY KEY (a, b))",
)
+ def test_create_table_exists(self):
+ m = MetaData()
+ t1 = Table("t1", m, Column("q", Integer))
+ self.assert_compile(
+ schema.CreateTable(t1, if_not_exists=True),
+ "CREATE TABLE IF NOT EXISTS t1 (q INTEGER)",
+ )
+
+ def test_drop_table_exists(self):
+ m = MetaData()
+ t1 = Table("t1", m, Column("q", Integer))
+ self.assert_compile(
+ schema.DropTable(t1, if_exists=True),
+ "DROP TABLE IF EXISTS t1",
+ )
+
+ def test_create_index_exists(self):
+ m = MetaData()
+ t1 = Table("t1", m, Column("q", Integer))
+ idx = Index("my_idx", t1.c.q)
+ self.assert_compile(
+ schema.CreateIndex(idx, if_not_exists=True),
+ "CREATE INDEX IF NOT EXISTS my_idx ON t1 (q)",
+ )
+
+ def test_drop_index_exists(self):
+ m = MetaData()
+ t1 = Table("t1", m, Column("q", Integer))
+ idx = Index("my_idx", t1.c.q)
+ self.assert_compile(
+ schema.DropIndex(idx, if_exists=True),
+ "DROP INDEX IF EXISTS my_idx",
+ )
+
def test_create_table_suffix(self):
class MyDialect(default.DefaultDialect):
class MyCompiler(compiler.DDLCompiler):