From 0bb5a9eab829f9a4cfda3c37cdf2202d84e55f3f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 1 Oct 2012 01:59:59 -0400 Subject: - 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. --- lib/sqlalchemy/schema.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/schema.py') diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index d7720a867..859ccd99b 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -2536,8 +2536,18 @@ class MetaData(SchemaItem): @property def sorted_tables(self): - """Returns a list of ``Table`` objects sorted in order of - dependency. + """Returns a list of :class:`.Table` objects sorted in order of + foreign key dependency. + + The sorting will place :class:`.Table` objects that have dependencies + first, before the dependencies themselves, representing the + order in which they can be created. To get the order in which + the tables would be dropped, use the ``reversed()`` Python built-in. + + .. seealso:: + + :meth:`.Inspector.sorted_tables` + """ return sqlutil.sort_tables(self.tables.itervalues()) @@ -3220,6 +3230,16 @@ class CreateTable(_CreateDropBase): for column in element.columns ] + +class _DropView(_CreateDropBase): + """Semi-public 'DROP VIEW' construct. + + Used by the test suite for dialect-agnostic drops of views. + This object will eventually be part of a public "view" API. + + """ + __visit_name__ = "drop_view" + class CreateColumn(visitors.Visitable): """Represent a :class:`.Column` as rendered in a CREATE TABLE statement, via the :class:`.CreateTable` construct. -- cgit v1.2.1