diff options
Diffstat (limited to 'migrate/changeset/schema.py')
-rw-r--r-- | migrate/changeset/schema.py | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/migrate/changeset/schema.py b/migrate/changeset/schema.py index 5a77208..073379c 100644 --- a/migrate/changeset/schema.py +++ b/migrate/changeset/schema.py @@ -12,6 +12,7 @@ from sqlalchemy.schema import UniqueConstraint from migrate.exceptions import * from migrate.changeset import SQLA_07, SQLA_08 +from migrate.changeset import util from migrate.changeset.databases.visitor import (get_engine_visitor, run_single_visitor) @@ -31,7 +32,7 @@ __all__ = [ def create_column(column, table=None, *p, **kw): """Create a column, given the table. - + API to :meth:`ChangesetColumn.create`. """ if table is not None: @@ -41,7 +42,7 @@ def create_column(column, table=None, *p, **kw): def drop_column(column, table=None, *p, **kw): """Drop a column, given the table. - + API to :meth:`ChangesetColumn.drop`. """ if table is not None: @@ -105,12 +106,12 @@ def alter_column(*p, **k): :param engine: The :class:`~sqlalchemy.engine.base.Engine` to use for table reflection and schema alterations. - + :returns: A :class:`ColumnDelta` instance representing the change. - + """ - + if 'table' not in k and isinstance(p[0], sqlalchemy.Column): k['table'] = p[0].table if 'engine' not in k: @@ -129,7 +130,7 @@ def alter_column(*p, **k): # that this crutch has to be left in until they can be sorted # out k['alter_metadata']=True - + delta = ColumnDelta(*p, **k) visitorcallable = get_engine_visitor(engine, 'schemachanger') @@ -183,10 +184,10 @@ class ColumnDelta(DictMixin, sqlalchemy.schema.SchemaItem): :param table: Table at which current Column should be bound to.\ If table name is given, reflection will be used. :type table: string or Table instance - + :param metadata: A :class:`MetaData` instance to store reflected table names - + :param engine: When reflecting tables, either engine or metadata must \ be specified to acquire engine object. :type engine: :class:`Engine` instance @@ -211,7 +212,7 @@ class ColumnDelta(DictMixin, sqlalchemy.schema.SchemaItem): # as a crutch until the tests that fail when 'alter_metadata' # behaviour always happens can be sorted out self.alter_metadata = kw.pop("alter_metadata", False) - + self.meta = kw.pop("metadata", None) self.engine = kw.pop("engine", None) @@ -239,7 +240,7 @@ class ColumnDelta(DictMixin, sqlalchemy.schema.SchemaItem): self.alter_metadata, super(ColumnDelta, self).__repr__() ) - + def __getitem__(self, key): if key not in self.keys(): raise KeyError("No such diff key, available: %s" % self.diffs ) @@ -278,7 +279,7 @@ class ColumnDelta(DictMixin, sqlalchemy.schema.SchemaItem): """Compares two Column objects""" self.process_column(new_col) self.table = k.pop('table', None) - # we cannot use bool() on table in SA06 + # we cannot use bool() on table in SA06 if self.table is None: self.table = old_col.table if self.table is None: @@ -482,7 +483,7 @@ class ChangesetColumn(object): def alter(self, *p, **k): """Makes a call to :func:`alter_column` for the column this - method is called on. + method is called on. """ if 'table' not in k: k['table'] = self.table @@ -560,12 +561,12 @@ populated with defaults def _col_name_in_constraint(self,cons,name): return False - + def remove_from_table(self, table, unset_table=True): # TODO: remove primary keys, constraints, etc if unset_table: self.table = None - + to_drop = set() for index in table.indexes: columns = [] @@ -579,7 +580,7 @@ populated with defaults else: to_drop.add(index) table.indexes = table.indexes - to_drop - + to_drop = set() for cons in table.constraints: # TODO: deal with other types of constraint @@ -591,7 +592,7 @@ populated with defaults if self.name==col_name: to_drop.add(cons) table.constraints = table.constraints - to_drop - + if table.c.contains_column(self): if SQLA_07: table._columns.remove(self) @@ -601,11 +602,12 @@ populated with defaults # TODO: this is fixed in 0.6 def copy_fixed(self, **kw): """Create a copy of this ``Column``, with all attributes.""" + q = util.safe_quote(self) return sqlalchemy.Column(self.name, self.type, self.default, key=self.key, primary_key=self.primary_key, nullable=self.nullable, - quote=self.quote, + quote=q, index=self.index, unique=self.unique, onupdate=self.onupdate, |