diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-16 13:08:45 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-16 13:08:45 -0400 |
commit | 23f8c6c241a457d88bcb470e37a5d23926195290 (patch) | |
tree | d8c7c75f464fdcd16cea9cf1d4fe33308dbd4b54 /lib/sqlalchemy/engine | |
parent | a4032d2929d82af81379893c3d2037ea253e929e (diff) | |
download | sqlalchemy-23f8c6c241a457d88bcb470e37a5d23926195290.tar.gz |
- Table.create() and Table.drop() no longer apply metadata-
level create/drop events. [ticket:1771]
Diffstat (limited to 'lib/sqlalchemy/engine')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/ddl.py | 14 |
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index d35796063..5068167c3 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -1497,14 +1497,14 @@ class Engine(Connectable, log.Identified): self.pool = self.pool.recreate() def create(self, entity, connection=None, **kwargs): - """Create a table or index within this engine's database connection given a schema.Table object.""" + """Create a table or index within this engine's database connection given a schema object.""" from sqlalchemy.engine import ddl self._run_visitor(ddl.SchemaGenerator, entity, connection=connection, **kwargs) def drop(self, entity, connection=None, **kwargs): - """Drop a table or index within this engine's database connection given a schema.Table object.""" + """Drop a table or index within this engine's database connection given a schema object.""" from sqlalchemy.engine import ddl diff --git a/lib/sqlalchemy/engine/ddl.py b/lib/sqlalchemy/engine/ddl.py index ef10aa5ea..74205dbb0 100644 --- a/lib/sqlalchemy/engine/ddl.py +++ b/lib/sqlalchemy/engine/ddl.py @@ -39,12 +39,15 @@ class SchemaGenerator(DDLBase): listener('before-create', metadata, self.connection, tables=collection) for table in collection: - self.traverse_single(table) + self.traverse_single(table, create_ok=True) for listener in metadata.ddl_listeners['after-create']: listener('after-create', metadata, self.connection, tables=collection) - def visit_table(self, table): + def visit_table(self, table, create_ok=False): + if not create_ok and not self._can_create(table): + return + for listener in table.ddl_listeners['before-create']: listener('before-create', table, self.connection) @@ -92,7 +95,7 @@ class SchemaDropper(DDLBase): listener('before-drop', metadata, self.connection, tables=collection) for table in collection: - self.traverse_single(table) + self.traverse_single(table, drop_ok=True) for listener in metadata.ddl_listeners['after-drop']: listener('after-drop', metadata, self.connection, tables=collection) @@ -106,7 +109,10 @@ class SchemaDropper(DDLBase): def visit_index(self, index): self.connection.execute(schema.DropIndex(index)) - def visit_table(self, table): + def visit_table(self, table, drop_ok=False): + if not drop_ok and not self._can_drop(table): + return + for listener in table.ddl_listeners['before-drop']: listener('before-drop', table, self.connection) |