summaryrefslogtreecommitdiff
path: root/migrate/changeset/schema.py
diff options
context:
space:
mode:
authorchrisw <unknown>2010-09-09 11:53:08 +0100
committerchrisw <unknown>2010-09-09 11:53:08 +0100
commita7c0c18a52649d1693cff6db7224477eeaa352c9 (patch)
tree38166ecf7db1723e0d817a20aabe3cb8159c71fd /migrate/changeset/schema.py
parent5cf42fbf76b035516d55ca0f1d7e95bb7365ae10 (diff)
downloadsqlalchemy-migrate-a7c0c18a52649d1693cff6db7224477eeaa352c9.tar.gz
Fix bug with column dropping involving foreign keys.
Bonus: remove_from_table now understands foreign keys
Diffstat (limited to 'migrate/changeset/schema.py')
-rw-r--r--migrate/changeset/schema.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/migrate/changeset/schema.py b/migrate/changeset/schema.py
index 5c62eb1..bf5aebe 100644
--- a/migrate/changeset/schema.py
+++ b/migrate/changeset/schema.py
@@ -2,10 +2,13 @@
Schema module providing common schema operations.
"""
import warnings
+
from UserDict import DictMixin
import sqlalchemy
+from sqlalchemy.schema import ForeignKeyConstraint
+
from migrate.exceptions import *
from migrate.changeset import SQLA_06
from migrate.changeset.databases.visitor import (get_engine_visitor,
@@ -571,6 +574,7 @@ populated with defaults
# TODO: remove primary keys, constraints, etc
if unset_table:
self.table = None
+
to_drop = set()
for index in table.indexes:
columns = []
@@ -582,6 +586,20 @@ 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
+ if isinstance(cons,ForeignKeyConstraint):
+ col_names = []
+ 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)
+ table.constraints = table.constraints - to_drop
+
if table.c.contains_column(self):
table.c.remove(self)