def upgrade(migrate_engine): """Add instance_system_metadata indexes missing on PostgreSQL and other DB. """ # This index was already added by migration 216 for MySQL if migrate_engine.name != 'mysql': # Adds index for PostgreSQL and other DB if not utils.index_exists(migrate_engine, SYS_META_TABLE_NAME, INDEX_NAME): utils.add_index(migrate_engine, SYS_META_TABLE_NAME, INDEX_NAME, INDEX_COLUMNS)
def upgrade(migrate_engine): meta = MetaData() meta.bind = migrate_engine if migrate_engine.name == 'sqlite': # SQLite is also missing this one index if not utils.index_exists(migrate_engine, 'fixed_ips', 'address'): utils.add_index(migrate_engine, 'fixed_ips', 'address', ['address']) for src_table, src_column, dst_table, dst_column, name in FKEYS: src_table = Table(src_table, meta, autoload=True) if name in set(fk.name for fk in src_table.foreign_keys): continue src_column = src_table.c[src_column] dst_table = Table(dst_table, meta, autoload=True) dst_column = dst_table.c[dst_column] fkey = ForeignKeyConstraint(columns=[src_column], refcolumns=[dst_column], name=name) fkey.create() # SQLAlchemy versions < 1.0.0 don't reflect unique constraints # for SQLite correctly causing sqlalchemy-migrate to recreate # some tables with missing unique constraints. Re-add some # potentially missing unique constraints as a workaround. for table_name, name, column_names in UNIQUES: table = Table(table_name, meta, autoload=True) if name in set(c.name for c in table.constraints if isinstance(table, schema.UniqueConstraint)): continue uc = UniqueConstraint(*column_names, table=table, name=name) uc.create()
def test_drop_index(self): Index('new_index', self.test_table.c.a).create(self.engine) utils.drop_index(self.engine, 'test_table', 'new_index') self.assertFalse(utils.index_exists(self.engine, 'test_table', 'new_index'))
def test_add_index(self): self.assertFalse(utils.index_exists(self.engine, 'test_table', 'new_index')) utils.add_index(self.engine, 'test_table', 'new_index', ('a',)) self.assertTrue(utils.index_exists(self.engine, 'test_table', 'new_index'))
def test_index_exists(self): self.assertFalse(utils.index_exists(self.engine, 'test_table', 'new_index')) Index('new_index', self.test_table.c.a).create(self.engine) self.assertTrue(utils.index_exists(self.engine, 'test_table', 'new_index'))
def assertIndexNotExists(self, engine, table_name, index): self.assertFalse(oslodbutils.index_exists(engine, table_name, index))
def assertIndexNotExists(self, engine, table_name, index): self.assertFalse(oslodbutils.index_exists(engine, table_name, index), 'Index %s on table %s should not exist' % (index, table_name))
def ensure_index_removed(migrate_engine, table_name, index_name): if utils.index_exists(migrate_engine, table_name, index_name): utils.drop_index(migrate_engine, table_name, index_name)
def assertIndexExists(self, engine, table_name, index): self.assertTrue( db_utils.index_exists(engine, table_name, index), "Index %s on table %s does not exist" % (index, table_name), )
def ensure_index_exists(migrate_engine, table_name, index_name, column_names): if not utils.index_exists(migrate_engine, table_name, index_name): utils.add_index(migrate_engine, table_name, index_name, column_names)
def assertIndexExists(self, engine, table_name, index): self.assertTrue(db_utils.index_exists(engine, table_name, index), 'Index {0!s} on table {1!s} does not exist'.format(index, table_name))
def assertIndexNotExists(self, engine, table_name, index): self.assertFalse(oslodbutils.index_exists(engine, table_name, index), 'Index {0!s} on table {1!s} should not exist'.format(index, table_name))
def assertIndexNotExists(self, connection, table_name, index): self.assertFalse( oslodbutils.index_exists(connection, table_name, index), 'Index %s on table %s should not exist' % (index, table_name), )
def assertIndexExists(self, engine, table_name, index): self.assertTrue(oslodbutils.index_exists(engine, table_name, index))
def assertIndexExists(self, engine, table_name, index): self.assertTrue(oslodbutils.index_exists(engine, table_name, index), 'Index %s on table %s does not exist' % (index, table_name))
def assertIndexNotExists(self, engine, table_name, index): self.assertFalse( oslodbutils.index_exists(engine, table_name, index), 'Index %s on table %s should not exist' % (index, table_name))
def assertIndexExists(self, engine, table_name, index): self.assertTrue( oslodbutils.index_exists(engine, table_name, index), 'Index %s on table %s does not exist' % (index, table_name))