summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/default.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-08-06 16:10:09 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-08-06 23:11:54 -0400
commitd8da7f5ac544f3dd853a221faa5fab4ff788e25b (patch)
tree0ec2fa102695a107eb799ed12c4ade60e84a8790 /lib/sqlalchemy/engine/default.py
parent6a622c636ca5bc55d96b92652fd43b914a77645c (diff)
downloadsqlalchemy-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/engine/default.py')
-rw-r--r--lib/sqlalchemy/engine/default.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py
index 9d457b800..fb1728eab 100644
--- a/lib/sqlalchemy/engine/default.py
+++ b/lib/sqlalchemy/engine/default.py
@@ -426,6 +426,15 @@ class DefaultDialect(interfaces.Dialect):
)
}
+ def has_index(self, connection, table_name, index_name, schema=None):
+ if not self.has_table(connection, table_name, schema=schema):
+ return False
+ for idx in self.get_indexes(connection, table_name, schema=schema):
+ if idx["name"] == index_name:
+ return True
+ else:
+ return False
+
def validate_identifier(self, ident):
if len(ident) > self.max_identifier_length:
raise exc.IdentifierError(