def test_add_index(self): meta = sqlalchemy.MetaData() table = _table('a', meta, sqlalchemy.Column('id', sqlalchemy.Integer)) meta.create_all(self.engine) index = sqlalchemy.Index('a_id_idx', table.c.id) op = sa_migration.AddIndex(index, {}) op.execute(self.ddlop) table = oslodbutils.get_table(self.engine, 'a') self.assertIn('a_id_idx', [i.name for i in table.indexes])
def test_remove_index_after_add(self): exist_meta = sqlalchemy.MetaData() oldtbl = sqlalchemy.Table('a', exist_meta, sqlalchemy.Column('id', sqlalchemy.Integer), sqlalchemy.Column('foo', sqlalchemy.Integer)) model_meta = sqlalchemy.MetaData() newtbl = sqlalchemy.Table('a', model_meta, sqlalchemy.Column('id', sqlalchemy.Integer)) old_index = sqlalchemy.Index('a_id_idx', oldtbl.c.id, oldtbl.c.foo) new_index = sqlalchemy.Index('a_id_idx', newtbl.c.id) dropidx = sa_migration.DropIndex(old_index) addidx = sa_migration.AddIndex(new_index, {}) scheduler = sa_migration.Scheduler() scheduler.add(addidx) scheduler.add(dropidx) expand, migrate, contract = scheduler.schedule() self.assertEqual([], expand) self.assertEqual([dropidx, addidx], migrate) self.assertEqual([], contract)