diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-10-01 01:59:59 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-10-01 01:59:59 -0400 |
commit | 0bb5a9eab829f9a4cfda3c37cdf2202d84e55f3f (patch) | |
tree | 2e7847e098ac547b5907c6650e219e9b0a65236e /lib/sqlalchemy/engine/reflection.py | |
parent | eaa15b3c70020b96aebd2e05651eb18226ff4ee3 (diff) | |
download | sqlalchemy-0bb5a9eab829f9a4cfda3c37cdf2202d84e55f3f.tar.gz |
- fix the fixture here that wasn't creating consistently
- rewrite --dropfirst to be more industrial strength, includes views
- fix order_by="foreign_key" to maintain the same ordering as
metadata.sorted_tables. Not ideal that this was the other way throughout
0.7 but this is still a little-used method, in contrast to metadata.sorted_tables.
Diffstat (limited to 'lib/sqlalchemy/engine/reflection.py')
-rw-r--r-- | lib/sqlalchemy/engine/reflection.py | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index 6373e8f10..4505aa18a 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -151,14 +151,32 @@ class Inspector(object): return [] def get_table_names(self, schema=None, order_by=None): - """Return all table names in `schema`. + """Return all table names in referred to within a particular schema. + + The names are expected to be real tables only, not views. + Views are instead returned using the :meth:`.get_view_names` + method. + + + :param schema: Schema name. If ``schema`` is left at ``None``, the + database's default schema is + used, else the named schema is searched. If the database does not + support named schemas, behavior is undefined if ``schema`` is not + passed as ``None``. - :param schema: Optional, retrieve names from a non-default schema. :param order_by: Optional, may be the string "foreign_key" to sort - the result on foreign key dependencies. + the result on foreign key dependencies. + + .. versionchanged:: 0.8 the "foreign_key" sorting sorts tables + in order of dependee to dependent; that is, in creation + order, rather than in drop order. This is to maintain + consistency with similar features such as + :attr:`.MetaData.sorted_tables` and :func:`.util.sort_tables`. + + .. seealso:: + + :attr:`.MetaData.sorted_tables` - This should probably not return view names or maybe it should return - them with an indicator t or v. """ if hasattr(self.dialect, 'get_table_names'): @@ -167,14 +185,11 @@ class Inspector(object): else: tnames = self.engine.table_names(schema) if order_by == 'foreign_key': - import random - random.shuffle(tnames) - tuples = [] for tname in tnames: for fkey in self.get_foreign_keys(tname, schema): if tname != fkey['referred_table']: - tuples.append((tname, fkey['referred_table'])) + tuples.append((fkey['referred_table'], tname)) tnames = list(topological.sort(tuples, tnames)) return tnames |