diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-07-19 22:13:29 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-07-19 22:13:29 +0000 |
commit | 8b50115acc7d249129aa8046839eefa2c611c453 (patch) | |
tree | f1788aef55e9563f97f413fe8c1a21ceb4c2366d /lib/sqlalchemy/ansisql.py | |
parent | 219730da27622f86e60db5be1dc179168614e5bc (diff) | |
download | sqlalchemy-8b50115acc7d249129aa8046839eefa2c611c453.tar.gz |
added 'checkfirst' argument to table.create()/table.drop()
some 0.2.6 prep
Diffstat (limited to 'lib/sqlalchemy/ansisql.py')
-rw-r--r-- | lib/sqlalchemy/ansisql.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ansisql.py b/lib/sqlalchemy/ansisql.py index 02423560b..3ba296576 100644 --- a/lib/sqlalchemy/ansisql.py +++ b/lib/sqlalchemy/ansisql.py @@ -602,6 +602,10 @@ class ANSICompiler(sql.Compiled): class ANSISchemaGenerator(engine.SchemaIterator): + def __init__(self, engine, proxy, connection=None, checkfirst=False, **params): + super(ANSISchemaGenerator, self).__init__(engine, proxy, **params) + self.checkfirst = checkfirst + self.connection = connection def get_column_specification(self, column, first_pk=False): raise NotImplementedError() @@ -609,6 +613,9 @@ class ANSISchemaGenerator(engine.SchemaIterator): # the single whitespace before the "(" is significant # as its MySQL's method of indicating a table name and not a reserved word. # feel free to localize this logic to the mysql module + if self.checkfirst and self.engine.dialect.has_table(self.connection, table.name): + return + self.append("\nCREATE TABLE " + table.fullname + " (") separator = "\n" @@ -682,6 +689,11 @@ class ANSISchemaGenerator(engine.SchemaIterator): class ANSISchemaDropper(engine.SchemaIterator): + def __init__(self, engine, proxy, connection=None, checkfirst=False, **params): + super(ANSISchemaDropper, self).__init__(engine, proxy, **params) + self.checkfirst = checkfirst + self.connection = connection + def visit_index(self, index): self.append("\nDROP INDEX " + index.name) self.execute() @@ -689,6 +701,8 @@ class ANSISchemaDropper(engine.SchemaIterator): def visit_table(self, table): # NOTE: indexes on the table will be automatically dropped, so # no need to drop them individually + if self.checkfirst and not self.engine.dialect.has_table(self.connection, table.name): + return self.append("\nDROP TABLE " + table.fullname) self.execute() |