Пример #1
0
def downgrade(migrate_engine):
    meta.bind = migrate_engine

    datastore_versions = Table('datastore_versions', meta, autoload=True)
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='clusters',
        columns=['datastore_version_id'],
        ref_table='datastore_versions',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[clusters.c.datastore_version_id],
        ref_columns=[datastore_versions.c.id])

    instances = Table('instances', meta, autoload=True)
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='instances',
        columns=['cluster_id'],
        ref_table='clusters',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[instances.c.cluster_id],
        ref_columns=[clusters.c.id])

    instances.drop_column('cluster_id')
    instances.drop_column('shard_id')
    instances.drop_column('type')

    drop_tables([clusters])
def upgrade(migrate_engine):
    meta.bind = migrate_engine

    instance_table = Table('instances', meta, autoload=True)
    datastore_versions_table = Table('datastore_versions', meta, autoload=True)

    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='instances',
        columns=[text('datastore_version_id')],
        ref_table='datastore_versions',
        ref_columns=[text('id')])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[instance_table.c.datastore_version_id],
        ref_columns=[datastore_versions_table.c.id])

    # Make datastore_version_id nullable so that this field could be set to
    # NULL when instance is deleted.
    instance_table.c.datastore_version_id.alter(nullable=True)

    db_utils.create_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[instance_table.c.datastore_version_id],
        ref_columns=[datastore_versions_table.c.id])
Пример #3
0
def downgrade(migrate_engine):
    meta.bind = migrate_engine

    datastore_versions = Table('datastore_versions', meta, autoload=True)
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='clusters',
        columns=['datastore_version_id'],
        ref_table='datastore_versions',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[clusters.c.datastore_version_id],
        ref_columns=[datastore_versions.c.id])

    instances = Table('instances', meta, autoload=True)
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='instances',
        columns=['cluster_id'],
        ref_table='clusters',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(constraint_names=constraint_names,
                                          columns=[instances.c.cluster_id],
                                          ref_columns=[clusters.c.id])

    instances.drop_column('cluster_id')
    instances.drop_column('shard_id')
    instances.drop_column('type')

    drop_tables([clusters])
Пример #4
0
def downgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine
    instances = Table("instances", meta, autoload=True)
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine, table="instances", columns=[COLUMN_NAME], ref_table="instances", ref_columns=["id"]
    )
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names, columns=[instances.c.slave_of_id], ref_columns=[instances.c.id]
    )
    instances.drop_column(COLUMN_NAME)
Пример #5
0
def downgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine
    instances = Table('instances', meta, autoload=True)
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='instances',
        columns=[COLUMN_NAME],
        ref_table='instances',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(constraint_names=constraint_names,
                                          columns=[instances.c.slave_of_id],
                                          ref_columns=[instances.c.id])
    instances.drop_column(COLUMN_NAME)
Пример #6
0
def downgrade(migrate_engine):
    meta.bind = migrate_engine
    instances = Table('instances', meta, autoload=True)
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='instances',
        columns=['configuration_id'],
        ref_table='configurations',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[instances.c.configuration_id],
        ref_columns=[configurations.c.id])
    instances.drop_column('configuration_id')
    drop_tables([configuration_parameters, configurations])
Пример #7
0
def downgrade(migrate_engine):
    meta.bind = migrate_engine
    instances = Table('instances', meta, autoload=True)
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='instances',
        columns=['configuration_id'],
        ref_table='configurations',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[instances.c.configuration_id],
        ref_columns=[configurations.c.id])
    instances.drop_column('configuration_id')
    drop_tables([configuration_parameters, configurations])
Пример #8
0
 def test_drop_foreign_key_constraints(self, mock_constraint):
     test_columns = [Column('col1', String(5)),
                     Column('col2', String(5))]
     test_refcolumns = [Column('ref_col1', String(5)),
                        Column('ref_col2', String(5))]
     test_constraint_names = ['constraint1', 'constraint2']
     db_utils.drop_foreign_key_constraints(test_constraint_names,
                                           test_columns,
                                           test_refcolumns)
     expected = [call(columns=test_columns,
                      refcolumns=test_refcolumns,
                      name='constraint1'),
                 call(columns=test_columns,
                      refcolumns=test_refcolumns,
                      name='constraint2')]
     self.assertEqual(expected, mock_constraint.call_args_list)
Пример #9
0
def downgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine
    backups = Table('backups', meta, autoload=True)
    datastore_versions = Table('datastore_versions', meta, autoload=True)
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='backups',
        columns=['datastore_version_id'],
        ref_table='datastore_versions',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[backups.c.datastore_version_id],
        ref_columns=[datastore_versions.c.id])
    backups.drop_column('datastore_version_id')
Пример #10
0
 def test_drop_foreign_key_constraints(self, mock_constraint):
     test_columns = [Column('col1', String(5)),
                     Column('col2', String(5))]
     test_refcolumns = [Column('ref_col1', String(5)),
                        Column('ref_col2', String(5))]
     test_constraint_names = ['constraint1', 'constraint2']
     db_utils.drop_foreign_key_constraints(test_constraint_names,
                                           test_columns,
                                           test_refcolumns)
     expected = [call(columns=test_columns,
                      refcolumns=test_refcolumns,
                      name='constraint1'),
                 call(columns=test_columns,
                      refcolumns=test_refcolumns,
                      name='constraint2')]
     self.assertEqual(expected, mock_constraint.call_args_list)
Пример #11
0
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    ds_table = Table('datastores', meta, autoload=True)
    ds_version_table = Table('datastore_versions', meta, autoload=True)
    ds_version_table.create_column(
        Column('version', String(255), nullable=True))

    ds_versions = select(columns=[text("id"), text("name")],
                         from_obj=ds_version_table).execute()

    # Use 'name' value as init 'version' value
    for version in ds_versions:
        update(table=ds_version_table,
               whereclause=text("id='%s'" % version.id),
               values=dict(version=version.name)).execute()

    # Change unique constraint, need to drop the foreign key first and add back
    # later
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='datastore_versions',
        columns=['datastore_id'],
        ref_table='datastores',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[ds_version_table.c.datastore_id],
        ref_columns=[ds_table.c.id])

    UniqueConstraint('datastore_id',
                     'name',
                     name='ds_versions',
                     table=ds_version_table).drop()
    UniqueConstraint('datastore_id',
                     'name',
                     'version',
                     name='ds_versions',
                     table=ds_version_table).create()

    db_utils.create_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[ds_version_table.c.datastore_id],
        ref_columns=[ds_table.c.id])
Пример #12
0
def downgrade(migrate_engine):
    meta.bind = migrate_engine
    instances = Table('instances', meta, autoload=True)
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='instances',
        columns=['datastore_version_id'],
        ref_table='datastore_versions',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[instances.c.datastore_version_id],
        ref_columns=[datastore_versions.c.id])
    instances.drop_column('datastore_version_id')
    service_type = Column('service_type', String(36))
    instances.create_column(service_type)
    instances.update().values({'service_type': 'mysql'}).execute()
    drop_tables([datastore_versions, datastores])
def downgrade(migrate_engine):
    meta.bind = migrate_engine
    clusters = Table('clusters', meta, autoload=True)
    configurations = Table('configurations', meta, autoload=True,
                           autoload_with=migrate_engine)

    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='clusters',
        columns=['configuration_id'],
        ref_table='configurations',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[clusters.c.configuration_id],
        ref_columns=[configurations.c.id])

    clusters.drop_column('configuration_id')
Пример #14
0
def downgrade(migrate_engine):
    meta.bind = migrate_engine
    instances = Table('instances', meta, autoload=True)
    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='instances',
        columns=['datastore_version_id'],
        ref_table='datastore_versions',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[instances.c.datastore_version_id],
        ref_columns=[datastore_versions.c.id])
    instances.drop_column('datastore_version_id')
    service_type = Column('service_type', String(36))
    instances.create_column(service_type)
    instances.update().values({'service_type': 'mysql'}).execute()
    drop_tables([datastore_versions, datastores])
Пример #15
0
def upgrade(migrate_engine):
    meta.bind = migrate_engine

    instance_table = Table('instances', meta, autoload=True)
    datastore_versions_table = Table('datastore_versions',
                                     meta,
                                     autoload=True)

    if has_instances_wo_datastore_version(instance_table):
        instances = find_all_instances_wo_datastore_version(instance_table)
        image_id = find_image("mysql")

        datastores_table = Table('datastores',
                                 meta,
                                 autoload=True)

        version_id = create_legacy_version(datastores_table,
                                           datastore_versions_table,
                                           image_id)
        for instance in instances:
            update(
                table=instance_table,
                whereclause="id='%s'" % instance.id,
                values=dict(datastore_version_id=version_id)
            ).execute()

    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='instances',
        columns=['datastore_version_id'],
        ref_table='datastore_versions',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[instance_table.c.datastore_version_id],
        ref_columns=[datastore_versions_table.c.id])

    instance_table.c.datastore_version_id.alter(nullable=False)

    db_utils.create_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[instance_table.c.datastore_version_id],
        ref_columns=[datastore_versions_table.c.id])
Пример #16
0
def upgrade(migrate_engine):
    meta.bind = migrate_engine

    instance_table = Table('instances', meta, autoload=True)
    datastore_versions_table = Table('datastore_versions', meta, autoload=True)

    if has_instances_wo_datastore_version(instance_table):
        instances = find_all_instances_wo_datastore_version(instance_table)
        image_id = find_image("mysql")

        datastores_table = Table('datastores', meta, autoload=True)

        version_id = create_legacy_version(datastores_table,
                                           datastore_versions_table, image_id)
        for instance in instances:
            update(table=instance_table,
                   whereclause="id='%s'" % instance.id,
                   values=dict(datastore_version_id=version_id)).execute()

    constraint_names = db_utils.get_foreign_key_constraint_names(
        engine=migrate_engine,
        table='instances',
        columns=['datastore_version_id'],
        ref_table='datastore_versions',
        ref_columns=['id'])
    db_utils.drop_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[instance_table.c.datastore_version_id],
        ref_columns=[datastore_versions_table.c.id])

    instance_table.c.datastore_version_id.alter(nullable=False)

    db_utils.create_foreign_key_constraints(
        constraint_names=constraint_names,
        columns=[instance_table.c.datastore_version_id],
        ref_columns=[datastore_versions_table.c.id])