コード例 #1
0
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)
コード例 #2
0
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()
コード例 #3
0
ファイル: test_utils.py プロジェクト: SvenDowideit/clearlinux
 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'))
コード例 #4
0
ファイル: test_utils.py プロジェクト: SvenDowideit/clearlinux
 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'))
コード例 #5
0
ファイル: test_utils.py プロジェクト: SvenDowideit/clearlinux
 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'))
コード例 #6
0
 def assertIndexNotExists(self, engine, table_name, index):
     self.assertFalse(oslodbutils.index_exists(engine, table_name, index))
コード例 #7
0
 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))
コード例 #8
0
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)
コード例 #9
0
 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),
     )
コード例 #10
0
 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'))
コード例 #11
0
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)
コード例 #12
0
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)
コード例 #13
0
ファイル: test_migrations.py プロジェクト: runt18/nova
 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))
コード例 #14
0
ファイル: test_migrations.py プロジェクト: runt18/nova
 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))
コード例 #15
0
 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),
     )
コード例 #16
0
ファイル: test_migrations.py プロジェクト: dtroyer/nova
 def assertIndexExists(self, engine, table_name, index):
     self.assertTrue(oslodbutils.index_exists(engine, table_name, index))
コード例 #17
0
ファイル: test_migrations.py プロジェクト: dtroyer/nova
 def assertIndexNotExists(self, engine, table_name, index):
     self.assertFalse(oslodbutils.index_exists(engine, table_name, index))
コード例 #18
0
 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'))
コード例 #19
0
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)
コード例 #20
0
 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'))
コード例 #21
0
 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))
コード例 #22
0
 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))
コード例 #23
0
 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))
コード例 #24
0
 def assertIndexExists(self, engine, table_name, index):
     self.assertTrue(oslodbutils.index_exists(engine, table_name, index))