def rename_with_constraints(meta, legacy_project_table_name,
                            new_project_table_name,
                            legacy_user_project_membership_table_name,
                            new_user_project_membership_table_name):
    # Not all RDBMSs support renaming a table that has foreign key constraints
    # on it, so drop FK constraints before renaming and then replace FKs
    # afterwards.

    credential_table = sql.Table('credential', meta, autoload=True)
    group_project_meta_table = sql.Table('group_project_metadata', meta,
                                         autoload=True)
    project_table = sql.Table(legacy_project_table_name, meta, autoload=True)
    user_project_membership_table = sql.Table(
        legacy_user_project_membership_table_name, meta, autoload=True)
    user_table = sql.Table('user', meta, autoload=True)

    constraints = [{'table': credential_table,
                    'fk_column': 'project_id',
                    'ref_column': project_table.c.id},
                   {'table': group_project_meta_table,
                    'fk_column': 'project_id',
                    'ref_column': project_table.c.id},
                   {'table': user_project_membership_table,
                    'fk_column': 'tenant_id',
                    'ref_column': project_table.c.id},
                   {'table': user_project_membership_table,
                    'fk_column': 'user_id',
                    'ref_column': user_table.c.id}]

    renames = {
        new_project_table_name: project_table,
        new_user_project_membership_table_name: user_project_membership_table}

    migration_helpers.rename_tables_with_constraints(renames, constraints,
                                                     meta.bind)
예제 #2
0
def upgrade(migrate_engine):
    """Create API-version specific endpoint tables."""
    meta = sql.MetaData()
    meta.bind = migrate_engine

    legacy_table = sql.Table('endpoint', meta, autoload=True)

    renames = {'endpoint_v2': legacy_table}
    service_table = sql.Table('service', meta, autoload=True)
    constraints = [{'table': legacy_table,
                    'fk_column': 'service_id',
                    'ref_column': service_table.c.id}]
    migration_helpers.rename_tables_with_constraints(renames, constraints,
                                                     migrate_engine)

    sql.Table('service', meta, autoload=True)
    new_table = sql.Table(
        'endpoint_v3',
        meta,
        sql.Column('id', sql.String(64), primary_key=True),
        sql.Column('legacy_endpoint_id', sql.String(64)),
        sql.Column('interface', sql.String(8), nullable=False),
        sql.Column('region', sql.String(255)),
        sql.Column('service_id',
                   sql.String(64),
                   sql.ForeignKey('service.id'),
                   nullable=False),
        sql.Column('url', sql.Text(), nullable=False),
        sql.Column('extra', sql.Text()))
    new_table.create(migrate_engine, checkfirst=True)
예제 #3
0
def upgrade(migrate_engine):
    """Create API-version specific endpoint tables."""
    meta = sql.MetaData()
    meta.bind = migrate_engine

    legacy_table = sql.Table('endpoint', meta, autoload=True)

    renames = {'endpoint_v2': legacy_table}
    service_table = sql.Table('service', meta, autoload=True)
    constraints = [{
        'table': legacy_table,
        'fk_column': 'service_id',
        'ref_column': service_table.c.id
    }]
    migration_helpers.rename_tables_with_constraints(renames, constraints,
                                                     migrate_engine)

    sql.Table('service', meta, autoload=True)
    new_table = sql.Table(
        'endpoint_v3', meta, sql.Column('id', sql.String(64),
                                        primary_key=True),
        sql.Column('legacy_endpoint_id', sql.String(64)),
        sql.Column('interface', sql.String(8), nullable=False),
        sql.Column('region', sql.String(255)),
        sql.Column('service_id',
                   sql.String(64),
                   sql.ForeignKey('service.id'),
                   nullable=False),
        sql.Column('url', sql.Text(), nullable=False),
        sql.Column('extra', sql.Text()))
    new_table.create(migrate_engine, checkfirst=True)
예제 #4
0
def rename_with_constraints(meta, legacy_project_table_name,
                            new_project_table_name,
                            legacy_user_project_membership_table_name,
                            new_user_project_membership_table_name):
    # Not all RDBMSs support renaming a table that has foreign key constraints
    # on it, so drop FK constraints before renaming and then replace FKs
    # afterwards.

    credential_table = sql.Table('credential', meta, autoload=True)
    group_project_meta_table = sql.Table('group_project_metadata', meta,
                                         autoload=True)
    project_table = sql.Table(legacy_project_table_name, meta, autoload=True)
    user_project_membership_table = sql.Table(
        legacy_user_project_membership_table_name, meta, autoload=True)
    user_table = sql.Table('user', meta, autoload=True)

    constraints = [{'table': credential_table,
                    'fk_column': 'project_id',
                    'ref_column': project_table.c.id},
                   {'table': group_project_meta_table,
                    'fk_column': 'project_id',
                    'ref_column': project_table.c.id},
                   {'table': user_project_membership_table,
                    'fk_column': 'tenant_id',
                    'ref_column': project_table.c.id},
                   {'table': user_project_membership_table,
                    'fk_column': 'user_id',
                    'ref_column': user_table.c.id}]

    renames = {
        new_project_table_name: project_table,
        new_user_project_membership_table_name: user_project_membership_table}

    migration_helpers.rename_tables_with_constraints(renames, constraints,
                                                     meta.bind)
예제 #5
0
def upgrade(migrate_engine):
    """Create API-version specific endpoint tables."""
    meta = sql.MetaData()
    meta.bind = migrate_engine

    legacy_table = sql.Table("endpoint", meta, autoload=True)

    renames = {"endpoint_v2": legacy_table}
    service_table = sql.Table("service", meta, autoload=True)
    constraints = [{"table": legacy_table, "fk_column": "service_id", "ref_column": service_table.c.id}]
    migration_helpers.rename_tables_with_constraints(renames, constraints, migrate_engine)

    sql.Table("service", meta, autoload=True)
    new_table = sql.Table(
        "endpoint_v3",
        meta,
        sql.Column("id", sql.String(64), primary_key=True),
        sql.Column("legacy_endpoint_id", sql.String(64)),
        sql.Column("interface", sql.String(8), nullable=False),
        sql.Column("region", sql.String(255)),
        sql.Column("service_id", sql.String(64), sql.ForeignKey("service.id"), nullable=False),
        sql.Column("url", sql.Text(), nullable=False),
        sql.Column("extra", sql.Text()),
    )
    new_table.create(migrate_engine, checkfirst=True)
예제 #6
0
def downgrade(migrate_engine):
    """Replace API-version specific endpoint tables with one based on v2."""
    meta = sql.MetaData()
    meta.bind = migrate_engine

    new_table = sql.Table("endpoint_v3", meta, autoload=True)
    new_table.drop()

    legacy_table = sql.Table("endpoint_v2", meta, autoload=True)

    renames = {"endpoint": legacy_table}
    service_table = sql.Table("service", meta, autoload=True)
    constraints = [{"table": legacy_table, "fk_column": "service_id", "ref_column": service_table.c.id}]
    migration_helpers.rename_tables_with_constraints(renames, constraints, migrate_engine)
예제 #7
0
def downgrade(migrate_engine):
    """Replace API-version specific endpoint tables with one based on v2."""
    meta = sql.MetaData()
    meta.bind = migrate_engine

    new_table = sql.Table('endpoint_v3', meta, autoload=True)
    new_table.drop()

    legacy_table = sql.Table('endpoint_v2', meta, autoload=True)

    renames = {'endpoint': legacy_table}
    service_table = sql.Table('service', meta, autoload=True)
    constraints = [{'table': legacy_table,
                    'fk_column': 'service_id',
                    'ref_column': service_table.c.id}]
    migration_helpers.rename_tables_with_constraints(renames, constraints,
                                                     migrate_engine)
예제 #8
0
def downgrade(migrate_engine):
    """Replace API-version specific endpoint tables with one based on v2."""
    meta = sql.MetaData()
    meta.bind = migrate_engine

    new_table = sql.Table('endpoint_v3', meta, autoload=True)
    new_table.drop()

    legacy_table = sql.Table('endpoint_v2', meta, autoload=True)

    renames = {'endpoint': legacy_table}
    service_table = sql.Table('service', meta, autoload=True)
    constraints = [{'table': legacy_table,
                    'fk_column': 'service_id',
                    'ref_column': service_table.c.id}]
    migration_helpers.rename_tables_with_constraints(renames, constraints,
                                                     migrate_engine)