diff options
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 14 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/util.py | 8 |
2 files changed, 13 insertions, 9 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 4a47df941..eacbe59e1 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -20,7 +20,7 @@ is otherwise internal to SQLAlchemy. import string, re from sqlalchemy import schema, engine, util, exc -from sqlalchemy.sql import operators, functions +from sqlalchemy.sql import operators, functions, util as sql_util from sqlalchemy.sql import expression as sql RESERVED_WORDS = set([ @@ -787,7 +787,11 @@ class SchemaGenerator(DDLBase): return not self.checkfirst or not self.dialect.has_table(self.connection, table.name, schema=table.schema) def visit_metadata(self, metadata): - collection = [t for t in metadata.table_iterator(reverse=False, tables=self.tables) if self._can_create(t)] + if self.tables: + tables = self.tables + else: + tables = metadata.tables.values() + collection = [t for t in sql_util.sort_tables(tables) if self._can_create(t)] for table in collection: self.traverse_single(table) if self.dialect.supports_alter: @@ -950,7 +954,11 @@ class SchemaDropper(DDLBase): self.dialect = dialect def visit_metadata(self, metadata): - collection = [t for t in metadata.table_iterator(reverse=True, tables=self.tables) if self._can_drop(t)] + if self.tables: + tables = self.tables + else: + tables = metadata.tables.values() + collection = [t for t in reversed(sql_util.sort_tables(tables)) if self._can_drop(t)] if self.dialect.supports_alter: for alterable in self.find_alterables(collection): self.drop_foreignkey(alterable) diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index ba6b5a605..e1636ccf9 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -4,7 +4,7 @@ from itertools import chain """Utility functions that build upon SQL and Schema constructs.""" -def sort_tables(tables, reverse=False): +def sort_tables(tables): """sort a collection of Table objects in order of their foreign-key dependency.""" tuples = [] @@ -18,11 +18,7 @@ def sort_tables(tables, reverse=False): for table in tables: visitors.traverse(table, {'schema_visitor':True}, {'foreign_key':visit_foreign_key}) - sequence = topological.sort(tuples, tables) - if reverse: - return reversed(sequence) - else: - return sequence + return topological.sort(tuples, tables) def search(clause, target): if not clause: |
