diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-01-04 21:12:31 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-01-04 21:12:31 -0500 |
commit | ecb3865615082301c2e5ab7f8e8a40bfbb99b05c (patch) | |
tree | 6a12d6c09d79f7655d867f5b6190d38d547b8584 /lib/sqlalchemy/sql/schema.py | |
parent | cad46c3cdca2bb914bcfc233fcbd3647eaf8ffe9 (diff) | |
download | sqlalchemy-ecb3865615082301c2e5ab7f8e8a40bfbb99b05c.tar.gz |
- The :paramref:`.Table.extend_existing` and :paramref:`.Table.autoload_replace`
parameters are now available on the :meth:`.MetaData.reflect`
method.
- starting to use paramref and need newer paramlinks version.
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r-- | lib/sqlalchemy/sql/schema.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 6205ada34..97c160bf5 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -2894,7 +2894,9 @@ class MetaData(SchemaItem): """ return ddl.sort_tables(self.tables.values()) - def reflect(self, bind=None, schema=None, views=False, only=None): + def reflect(self, bind=None, schema=None, views=False, only=None, + extend_existing=False, + autoload_replace=True): """Load all available table definitions from the database. Automatically creates ``Table`` entries in this ``MetaData`` for any @@ -2929,6 +2931,17 @@ class MetaData(SchemaItem): with a table name and this ``MetaData`` instance as positional arguments and should return a true value for any table to reflect. + :param extend_existing: Passed along to each :class:`.Table` as + :paramref:`.Table.extend_existing`. + + .. versionadded:: 0.9.1 + + :param autoload_replace: Passed along to each :class:`.Table` as + :paramref:`.Table.autoload_replace`. + + .. versionadded:: 0.9.1 + + """ if bind is None: bind = _bind_or_error(self) @@ -2937,7 +2950,9 @@ class MetaData(SchemaItem): reflect_opts = { 'autoload': True, - 'autoload_with': conn + 'autoload_with': conn, + 'extend_existing': extend_existing, + 'autoload_replace': autoload_replace } if schema is None: @@ -2963,12 +2978,13 @@ class MetaData(SchemaItem): if only is None: load = [name for name, schname in - zip(available, available_w_schema) - if schname not in current] + zip(available, available_w_schema) + if extend_existing or schname not in current] elif util.callable(only): load = [name for name, schname in zip(available, available_w_schema) - if schname not in current and only(name, self)] + if (extend_existing or schname not in current) + and only(name, self)] else: missing = [name for name in only if name not in available] if missing: @@ -2977,7 +2993,8 @@ class MetaData(SchemaItem): 'Could not reflect: requested table(s) not available ' 'in %s%s: (%s)' % (bind.engine.url, s, ', '.join(missing))) - load = [name for name in only if name not in current] + load = [name for name in only if extend_existing or + name not in current] for name in load: Table(name, self, **reflect_opts) |