From adf4113a0b8465dc67ea4002da3bc153eb4653db Mon Sep 17 00:00:00 2001 From: chrisw Date: Thu, 9 Sep 2010 15:38:42 +0100 Subject: Fix issue 94 - it was impossible to add a column with a non-unique index. Also implement more functionality with unique and foreign key constrains for sqlite. --- migrate/changeset/schema.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'migrate/changeset/schema.py') diff --git a/migrate/changeset/schema.py b/migrate/changeset/schema.py index bf5aebe..ef8dd85 100644 --- a/migrate/changeset/schema.py +++ b/migrate/changeset/schema.py @@ -8,6 +8,7 @@ from UserDict import DictMixin import sqlalchemy from sqlalchemy.schema import ForeignKeyConstraint +from sqlalchemy.schema import UniqueConstraint from migrate.exceptions import * from migrate.changeset import SQLA_06 @@ -570,6 +571,9 @@ populated with defaults if table is not None and self.table is None: self._set_parent(table) + 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: @@ -590,14 +594,13 @@ populated with defaults to_drop = set() for cons in table.constraints: # TODO: deal with other types of constraint - if isinstance(cons,ForeignKeyConstraint): - col_names = [] + if isinstance(cons,(ForeignKeyConstraint, + UniqueConstraint)): for col_name in cons.columns: if not isinstance(col_name,basestring): col_name = col_name.name - col_names.append(col_name) - if self.name in col_names: - to_drop.add(cons) + if self.name==col_name: + to_drop.add(cons) table.constraints = table.constraints - to_drop if table.c.contains_column(self): -- cgit v1.2.1