summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/schema.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-02-01 20:47:02 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2013-02-01 20:47:02 -0500
commitda3d817f3624d5f631956e33d92799572f47e52f (patch)
tree44f5849c205d30af1102556355e841e7ec90614d /lib/sqlalchemy/schema.py
parent096a9cec1471c56c66393ea80de787645bec2a74 (diff)
downloadsqlalchemy-da3d817f3624d5f631956e33d92799572f47e52f.tar.gz
Added a new argument to :class:`.Enum` and its base
:class:`.SchemaType` ``inherit_schema``. When set to ``True``, the type will set its ``schema`` attribute of that of the :class:`.Table` to which it is associated. This also occurs during a :meth:`.Table.tometadata` operation; the :class:`.SchemaType` is now copied in all cases when :meth:`.Table.tometadata` happens, and if ``inherit_schema=True``, the type will take on the new schema name passed to the method. The ``schema`` is important when used with the Postgresql backend, as the type results in a ``CREATE TYPE`` statement. [ticket:2657]
Diffstat (limited to 'lib/sqlalchemy/schema.py')
-rw-r--r--lib/sqlalchemy/schema.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py
index b9ee55abf..9d14bd3ca 100644
--- a/lib/sqlalchemy/schema.py
+++ b/lib/sqlalchemy/schema.py
@@ -634,16 +634,26 @@ class Table(SchemaItem, expression.TableClause):
E.g.::
+ some_engine = create_engine("sqlite:///some.db")
+
# create two metadata
- meta1 = MetaData('sqlite:///querytest.db')
+ meta1 = MetaData()
meta2 = MetaData()
# load 'users' from the sqlite engine
- users_table = Table('users', meta1, autoload=True)
+ users_table = Table('users', meta1, autoload=True,
+ autoload_with=some_engine)
# create the same Table object for the plain metadata
users_table_2 = users_table.tometadata(meta2)
+ :param metadata: Target :class:`.MetaData` object.
+ :param schema: Optional string name of a target schema, or
+ ``None`` for no schema. The :class:`.Table` object will be
+ given this schema name upon copy. Defaults to the special
+ symbol :attr:`.RETAIN_SCHEMA` which indicates no change should be
+ made to the schema name of the resulting :class:`.Table`.
+
"""
if schema is RETAIN_SCHEMA:
@@ -1094,9 +1104,13 @@ class Column(SchemaItem, expression.ColumnClause):
[c.copy(**kw) for c in self.constraints] + \
[c.copy(**kw) for c in self.foreign_keys if not c.constraint]
+ type_ = self.type
+ if isinstance(type_, sqltypes.SchemaType):
+ type_ = type_.copy(**kw)
+
c = self._constructor(
name=self.name,
- type_=self.type,
+ type_=type_,
key=self.key,
primary_key=self.primary_key,
nullable=self.nullable,