diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-06 16:10:09 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-06 23:11:54 -0400 |
| commit | d8da7f5ac544f3dd853a221faa5fab4ff788e25b (patch) | |
| tree | 0ec2fa102695a107eb799ed12c4ade60e84a8790 /lib/sqlalchemy/testing/suite/test_reflection.py | |
| parent | 6a622c636ca5bc55d96b92652fd43b914a77645c (diff) | |
| download | sqlalchemy-d8da7f5ac544f3dd853a221faa5fab4ff788e25b.tar.gz | |
Implement checkfirst for Index.create(), Index.drop()
The :meth:`.Index.create` and :meth:`.Index.drop` methods now have a
parameter :paramref:`.Index.create.checkfirst`, in the same way as that of
:class:`.Table` and :class:`.Sequence`, which when enabled will cause the
operation to detect if the index exists (or not) before performing a create
or drop operation.
Fixes: #527
Change-Id: Idf994bc016359d0ae86cc64ccb20378115cb66d6
Diffstat (limited to 'lib/sqlalchemy/testing/suite/test_reflection.py')
| -rw-r--r-- | lib/sqlalchemy/testing/suite/test_reflection.py | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index 9ca13ec4e..9b6cec10c 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -77,6 +77,65 @@ class HasTableTest(fixtures.TablesTest): ) +class HasIndexTest(fixtures.TablesTest): + __backend__ = True + + @classmethod + def define_tables(cls, metadata): + tt = Table( + "test_table", + metadata, + Column("id", Integer, primary_key=True), + Column("data", String(50)), + ) + Index("my_idx", tt.c.data) + + if testing.requires.schemas.enabled: + tt = Table( + "test_table", + metadata, + Column("id", Integer, primary_key=True), + Column("data", String(50)), + schema=config.test_schema, + ) + Index("my_idx_s", tt.c.data) + + def test_has_index(self): + with config.db.begin() as conn: + assert config.db.dialect.has_index(conn, "test_table", "my_idx") + assert not config.db.dialect.has_index( + conn, "test_table", "my_idx_s" + ) + assert not config.db.dialect.has_index( + conn, "nonexistent_table", "my_idx" + ) + assert not config.db.dialect.has_index( + conn, "test_table", "nonexistent_idx" + ) + + @testing.requires.schemas + def test_has_index_schema(self): + with config.db.begin() as conn: + assert config.db.dialect.has_index( + conn, "test_table", "my_idx_s", schema=config.test_schema + ) + assert not config.db.dialect.has_index( + conn, "test_table", "my_idx", schema=config.test_schema + ) + assert not config.db.dialect.has_index( + conn, + "nonexistent_table", + "my_idx_s", + schema=config.test_schema, + ) + assert not config.db.dialect.has_index( + conn, + "test_table", + "nonexistent_idx_s", + schema=config.test_schema, + ) + + class ComponentReflectionTest(fixtures.TablesTest): run_inserts = run_deletes = None @@ -1129,4 +1188,9 @@ class NormalizedNameTest(fixtures.TablesTest): eq_(tablenames[1].upper(), tablenames[1].lower()) -__all__ = ("ComponentReflectionTest", "HasTableTest", "NormalizedNameTest") +__all__ = ( + "ComponentReflectionTest", + "HasTableTest", + "HasIndexTest", + "NormalizedNameTest", +) |
