def downgrade_enterprise_dbs(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    for table_name in all_tables:
        table = Table(table_name, meta, autoload=True)

        old_deleted = Column('old_deleted', Boolean, default=False)
        old_deleted.create(table, populate_default=False)

        table.update().\
                where(table.c.deleted == table.c.id).\
                values(old_deleted=True).\
                execute()

        table.c.deleted.drop()
        table.c.old_deleted.alter(name="deleted")

    # NOTE(jhesketh): Unfortunately indexes were lost with this upgrade
    # so we need to recreate them so the downgrade is consistent with
    # the previous state.

    if migrate_engine.name == "mysql":
        # NOTE(jhesketh): MySQL kept the second index due to migration 144
        # where it was added with a truncated key to be compatible with
        # mysql.
        sql = ("drop index migrations_by_host_nodes_and_status_idx ON "
               "migrations")
        migrate_engine.execute(sql)

        sql = ("create index migrations_by_host_nodes_and_status_idx ON "
               "migrations (deleted, source_compute(100), "
               "dest_compute(100), source_node(100), dest_node(100), "
               "status)")

        migrate_engine.execute(sql)
    else:
        lost_indexes_data['migrations'] = ((
            'migrations_instance_uuid_and_status_idx',
            ('instance_uuid', 'status'),
            ('deleted', 'instance_uuid', 'status'),
        ), (
            'migrations_by_host_nodes_and_status_idx',
            ('source_compute', 'dest_compute', 'source_node',
             'dest_node', 'status'),
            ('deleted', 'source_compute', 'dest_compute', 'source_node',
             'dest_node', 'status'),
        ))

    utils.modify_indexes(migrate_engine, lost_indexes_data)
Ejemplo n.º 2
0
    def test_modify_indexes_checks_index_before_dropping_in_mysql(self):
        data = {"table_name": (('index2', ('old_column'),
                                ('new_column')),)}
        migrate_engine = mock.Mock()
        migrate_engine.name = 'mysql'

        with mock.patch('nova.db.sqlalchemy.utils.reflection.Inspector'
                        '.from_engine') as inspector:
            inspector.return_value.get_indexes.return_value = [
                {'name': "index1"}]
            with mock.patch('nova.db.sqlalchemy.utils.Index') as index:
                with mock.patch('nova.db.sqlalchemy.utils.Table') as Table:
                    index.return_value = mock.Mock()
                    utils.modify_indexes(migrate_engine, data, False)

                    self.assertFalse(index.return_value.drop.called)
Ejemplo n.º 3
0
    def test_modify_indexes_checks_index_before_dropping_in_mysql(self):
        data = {"table_name": (('index2', ('old_column'), ('new_column')), )}
        migrate_engine = mock.Mock()
        migrate_engine.name = 'mysql'

        with mock.patch('nova.db.sqlalchemy.utils.reflection.Inspector'
                        '.from_engine') as inspector:
            inspector.return_value.get_indexes.return_value = [{
                'name': "index1"
            }]
            with mock.patch('nova.db.sqlalchemy.utils.Index') as index:
                with mock.patch('nova.db.sqlalchemy.utils.Table') as Table:
                    index.return_value = mock.Mock()
                    utils.modify_indexes(migrate_engine, data, False)

                    self.assertFalse(index.return_value.drop.called)
def downgrade(migrate_engine):
    if migrate_engine.name == 'mysql':
        # NOTE(jhesketh): MySQL Cannot drop index
        # migrations_instance_uuid_and_status_idx needed in a foreign
        # key constraint. So we'll remove the fkey constraint on the
        # aggregate_metadata table and add it back after the indexes are
        # downgraded.
        meta = MetaData(bind=migrate_engine)
        table = Table('migrations', meta, autoload=True)
        ref_table = Table('instances', meta, autoload=True)
        params = {'columns': [table.c['instance_uuid']],
                  'refcolumns': [ref_table.c['uuid']]}
        if migrate_engine.name == 'mysql':
            params['name'] = 'fk_migrations_instance_uuid'
        fkey = ForeignKeyConstraint(**params)
        fkey.drop()

    utils.modify_indexes(migrate_engine, data, upgrade=False)

    if migrate_engine.name == 'mysql':
        fkey.create()
def downgrade(migrate_engine):
    if migrate_engine.name == 'mysql':
        # NOTE(jhesketh): MySQL Cannot drop index
        # migrations_instance_uuid_and_status_idx needed in a foreign
        # key constraint. So we'll remove the fkey constraint on the
        # aggregate_metadata table and add it back after the indexes are
        # downgraded.
        meta = MetaData(bind=migrate_engine)
        table = Table('migrations', meta, autoload=True)
        ref_table = Table('instances', meta, autoload=True)
        params = {
            'columns': [table.c['instance_uuid']],
            'refcolumns': [ref_table.c['uuid']]
        }
        if migrate_engine.name == 'mysql':
            params['name'] = 'fk_migrations_instance_uuid'
        fkey = ForeignKeyConstraint(**params)
        fkey.drop()

    utils.modify_indexes(migrate_engine, data, upgrade=False)

    if migrate_engine.name == 'mysql':
        fkey.create()
Ejemplo n.º 6
0
def downgrade(migrate_engine):
    return utils.modify_indexes(migrate_engine, data, upgrade=False)
Ejemplo n.º 7
0
def upgrade(migrate_engine):
    return utils.modify_indexes(migrate_engine, data)
def downgrade(migrate_engine):
    return utils.modify_indexes(migrate_engine, data, upgrade=False)
def upgrade(migrate_engine):
    return utils.modify_indexes(migrate_engine, data)