def add_constraint(self, const):
self._exec(schema.AddConstraint(const))
+ def drop_constraint(self, const):
+ self._exec(schema.DropConstraint(const))
+
def create_table(self, table):
self._exec(schema.CreateTable(table))
for index in table.indexes:
'alter_column',
'add_column',
'drop_column',
+ 'drop_constraint',
'create_foreign_key',
'create_table',
'drop_table',
def _unique_constraint(name, source, local_cols, **kw):
t = schema.Table(source, schema.MetaData(),
*[schema.Column(n, NULLTYPE) for n in local_cols])
- return schema.UniqueConstraint(*t.c, name=name, **kw)
+ uq = schema.UniqueConstraint(*t.c, name=name, **kw)
+ # TODO: need event tests to ensure the event
+ # is fired off here
+ t.append_constraint(uq)
+ return uq
def _table(name, *columns, **kw):
m = schema.MetaData()
"""
get_impl().drop_index(_index(name, 'foo', []))
+def drop_constraint(name, tablename):
+ """Drop a constraint of the given name"""
+ t = _table(tablename)
+ const = schema.Constraint(name=name)
+ t.append_constraint(const)
+ get_impl().drop_constraint(const)
+
def bulk_insert(table, rows):
"""Issue a "bulk insert" operation using the current change context.
"ALTER TABLE t1 ADD CONSTRAINT uk_test UNIQUE (foo, bar)"
)
+def test_drop_constraint():
+ context = _op_fixture()
+ op.drop_constraint('foo_bar_bat', 't1')
+ context.assert_(
+ "ALTER TABLE t1 DROP CONSTRAINT foo_bar_bat"
+ )
+
def test_create_index():
context = _op_fixture()
op.create_index('ik_test', 't1', ['foo', 'bar'])