From d8da7f5ac544f3dd853a221faa5fab4ff788e25b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 6 Aug 2019 16:10:09 -0400 Subject: 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 --- lib/sqlalchemy/sql/schema.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/sqlalchemy/sql/schema.py') diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 091012896..d9667e445 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -3670,7 +3670,7 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem): return self.table.bind - def create(self, bind=None): + def create(self, bind=None, checkfirst=False): """Issue a ``CREATE`` statement for this :class:`.Index`, using the given :class:`.Connectable` for connectivity. @@ -3682,10 +3682,10 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem): """ if bind is None: bind = _bind_or_error(self) - bind._run_ddl_visitor(ddl.SchemaGenerator, self) + bind._run_ddl_visitor(ddl.SchemaGenerator, self, checkfirst=checkfirst) return self - def drop(self, bind=None): + def drop(self, bind=None, checkfirst=False): """Issue a ``DROP`` statement for this :class:`.Index`, using the given :class:`.Connectable` for connectivity. @@ -3697,7 +3697,7 @@ class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem): """ if bind is None: bind = _bind_or_error(self) - bind._run_ddl_visitor(ddl.SchemaDropper, self) + bind._run_ddl_visitor(ddl.SchemaDropper, self, checkfirst=checkfirst) def __repr__(self): return "Index(%s)" % ( -- cgit v1.2.1