Esempio n. 1
0
def upgrade(migrate_engine):
    meta = sql.MetaData()
    meta.bind = migrate_engine

    project_table = sql.Table('project', meta, autoload=True)
    parent_id = sql.Column('parent_id', sql.String(64))
    project_table.create_column(parent_id)

    if migrate_engine.name == 'sqlite':
        return
    migration_helpers.add_constraints(list_constraints(project_table))
def upgrade(migrate_engine):
    meta = sql.MetaData()
    meta.bind = migrate_engine

    project_table = sql.Table('project', meta, autoload=True)
    parent_id = sql.Column('parent_id', sql.String(64))
    project_table.create_column(parent_id)

    if migrate_engine.name == 'sqlite':
        return
    migration_helpers.add_constraints(list_constraints(project_table))
Esempio n. 3
0
def upgrade(migrate_engine):
    meta = sql.MetaData()
    meta.bind = migrate_engine

    project_table = sql.Table(_PROJECT_TABLE_NAME, meta, autoload=True)
    parent_id = sql.Column(_PARENT_ID_COLUMN_NAME, sql.String(64),
                           nullable=True)
    project_table.create_column(parent_id)

    if migrate_engine.name == 'sqlite':
        return
    migration_helpers.add_constraints(list_constraints(project_table))
Esempio n. 4
0
def upgrade(migrate_engine):
    meta = sql.MetaData()
    meta.bind = migrate_engine

    project_table = sql.Table(_PROJECT_TABLE_NAME, meta, autoload=True)
    parent_id = sql.Column(_PARENT_ID_COLUMN_NAME, sql.String(64),
                           nullable=True)
    project_table.create_column(parent_id)

    if migrate_engine.name == 'sqlite':
        return
    migration_helpers.add_constraints(list_constraints(project_table))
def upgrade(migrate_engine):
    # Upgrade operations go here. Don't create your own engine; bind
    # migrate_engine to your metadata
    meta = sql.MetaData()
    meta.bind = migrate_engine

    consumer_table = sql.Table('consumer', meta, autoload=True)
    request_token_table = sql.Table('request_token', meta, autoload=True)
    access_token_table = sql.Table('access_token', meta, autoload=True)

    constraints = [{'table': request_token_table,
                    'fk_column': 'consumer_id',
                    'ref_column': consumer_table.c.id},
                   {'table': access_token_table,
                    'fk_column': 'consumer_id',
                    'ref_column': consumer_table.c.id}]
    if meta.bind != 'sqlite':
        migration_helpers.add_constraints(constraints)
Esempio n. 6
0
def upgrade(migrate_engine):
    # Upgrade operations go here. Don't create your own engine; bind
    # migrate_engine to your metadata
    meta = sql.MetaData()
    meta.bind = migrate_engine

    consumer_table = sql.Table('consumer', meta, autoload=True)
    request_token_table = sql.Table('request_token', meta, autoload=True)
    access_token_table = sql.Table('access_token', meta, autoload=True)

    constraints = [{
        'table': request_token_table,
        'fk_column': 'consumer_id',
        'ref_column': consumer_table.c.id
    }, {
        'table': access_token_table,
        'fk_column': 'consumer_id',
        'ref_column': consumer_table.c.id
    }]
    if meta.bind != 'sqlite':
        migration_helpers.add_constraints(constraints)
def downgrade(migrate_engine):
    if migrate_engine.name == 'sqlite':
        return
    migration_helpers.add_constraints(list_constraints(migrate_engine))
def downgrade(migrate_engine):
    if migrate_engine.name == 'sqlite':
        return
    migration_helpers.add_constraints(list_constraints(migrate_engine))
Esempio n. 9
0
def upgrade(migrate_engine):

    def _project_from_domain(domain):
        # Creates a project dict with is_domain=True from the provided
        # domain.

        description = None
        extra = {}
        if domain.extra is not None:
            # 'description' property is an extra attribute in domains but a
            # first class attribute in projects
            extra = json.loads(domain.extra)
            description = extra.pop('description', None)

        return {
            'id': domain.id,
            'name': domain.name,
            'enabled': domain.enabled,
            'description': description,
            'domain_id': NULL_DOMAIN_ID,
            'is_domain': True,
            'parent_id': None,
            'extra': json.dumps(extra)
        }

    meta = sql.MetaData()
    meta.bind = migrate_engine
    session = sql.orm.sessionmaker(bind=migrate_engine)()

    project_table = sql.Table(_PROJECT_TABLE_NAME, meta, autoload=True)
    domain_table = sql.Table(_DOMAIN_TABLE_NAME, meta, autoload=True)

    # NOTE(htruta): Remove the parent_id constraint during the migration
    # because for every root project inside this domain, we will set
    # the project domain_id to be its parent_id. We re-enable the constraint
    # in the end of this method. We also remove the domain_id constraint,
    # while be recreated a FK to the project_id at the end.
    migration_helpers.remove_constraints(
        list_existing_project_constraints(project_table, domain_table))

    # For each domain, create a project acting as a domain. We ignore the
    # "root of all domains" row, since we already have one of these in the
    # project table.
    domains = list(domain_table.select().execute())
    for domain in domains:
        if domain.id == NULL_DOMAIN_ID:
            continue
        is_domain_project = _project_from_domain(domain)
        new_entry = project_table.insert().values(**is_domain_project)
        session.execute(new_entry)
        session.commit()

    # For each project, that has no parent (i.e. a top level project), update
    # it's parent_id to point at the project acting as its domain. We ignore
    # the "root of all domains" row, since its parent_id must always be None.
    projects = list(project_table.select().execute())
    for project in projects:
        if (project.parent_id is not None or project.is_domain or
                project.id == NULL_DOMAIN_ID):
            continue
        values = {'parent_id': project.domain_id}
        update = project_table.update().where(
            project_table.c.id == project.id).values(values)
        session.execute(update)
        session.commit()

    migration_helpers.add_constraints(
        list_new_project_constraints(project_table))

    session.close()
def upgrade(migrate_engine):
    # Upgrade operations go here. Don't create your own engine;
    # bind migrate_engine to your metadata

    if migrate_engine.name != 'mysql':
        # InnoDB / MyISAM only applies to MySQL.
        return

    # This is a list of all the tables that might have been created with MyISAM
    # rather than InnoDB.
    tables = [
        'credential',
        'domain',
        'ec2_credential',
        'endpoint',
        'group',
        'group_domain_metadata',
        'group_project_metadata',
        'policy',
        'project',
        'role',
        'service',
        'token',
        'trust',
        'trust_role',
        'user',
        'user_domain_metadata',
        'user_group_membership',
        'user_project_metadata',
    ]

    meta = MetaData()
    meta.bind = migrate_engine

    domain_table = sql.Table('domain', meta, autoload=True)
    endpoint_table = sql.Table('endpoint', meta, autoload=True)
    group_table = sql.Table('group', meta, autoload=True)
    group_domain_metadata_table = sql.Table('group_domain_metadata',
                                            meta,
                                            autoload=True)
    group_project_metadata_table = sql.Table('group_project_metadata',
                                             meta,
                                             autoload=True)
    project_table = sql.Table('project', meta, autoload=True)
    service_table = sql.Table('service', meta, autoload=True)
    user_table = sql.Table('user', meta, autoload=True)
    user_domain_metadata_table = sql.Table('user_domain_metadata',
                                           meta,
                                           autoload=True)
    user_group_membership_table = sql.Table('user_group_membership',
                                            meta,
                                            autoload=True)

    # Mapping of table name to the constraints on that table,
    # so we can create them.
    table_constraints = {
        'endpoint': [
            {
                'table': endpoint_table,
                'fk_column': 'service_id',
                'ref_column': service_table.c.id
            },
        ],
        'group': [
            {
                'table': group_table,
                'fk_column': 'domain_id',
                'ref_column': domain_table.c.id
            },
        ],
        'group_domain_metadata': [
            {
                'table': group_domain_metadata_table,
                'fk_column': 'domain_id',
                'ref_column': domain_table.c.id
            },
        ],
        'group_project_metadata': [
            {
                'table': group_project_metadata_table,
                'fk_column': 'project_id',
                'ref_column': project_table.c.id
            },
        ],
        'project': [
            {
                'table': project_table,
                'fk_column': 'domain_id',
                'ref_column': domain_table.c.id
            },
        ],
        'user': [
            {
                'table': user_table,
                'fk_column': 'domain_id',
                'ref_column': domain_table.c.id
            },
        ],
        'user_domain_metadata': [
            {
                'table': user_domain_metadata_table,
                'fk_column': 'domain_id',
                'ref_column': domain_table.c.id
            },
        ],
        'user_group_membership': [
            {
                'table': user_group_membership_table,
                'fk_column': 'user_id',
                'ref_column': user_table.c.id
            },
            {
                'table': user_group_membership_table,
                'fk_column': 'group_id',
                'ref_column': group_table.c.id
            },
        ],
        'user_project_metadata': [
            {
                'table': group_project_metadata_table,
                'fk_column': 'project_id',
                'ref_column': project_table.c.id
            },
        ],
    }

    # Maps a table name to the tables that reference it as a FK constraint
    # (See the map above).
    ref_tables_map = {
        'service': [
            'endpoint',
        ],
        'domain': [
            'group',
            'group_domain_metadata',
            'project',
            'user',
            'user_domain_metadata',
        ],
        'project': [
            'group_project_metadata',
            'user_project_metadata',
        ],
        'user': [
            'user_group_membership',
        ],
        'group': [
            'user_group_membership',
        ],
    }

    # The names of tables that need to have their FKs added.
    fk_table_names = set()

    d = migrate_engine.execute("SHOW TABLE STATUS WHERE Engine!='InnoDB';")
    for row in d.fetchall():
        table_name = row[0]

        if table_name not in tables:
            # Skip this table since it's not a Keystone table.
            continue

        migrate_engine.execute("ALTER TABLE `%s` Engine=InnoDB" % table_name)

        # Will add the FKs to the table if any of
        # a) the table itself was converted
        # b) the tables that the table referenced were converted

        if table_name in table_constraints:
            fk_table_names.add(table_name)

        ref_tables = ref_tables_map.get(table_name, [])
        for other_table_name in ref_tables:
            fk_table_names.add(other_table_name)

    # Now add all the FK constraints to those tables
    for table_name in fk_table_names:
        constraints = table_constraints.get(table_name)
        migration_helpers.add_constraints(constraints)
def upgrade(migrate_engine):
    # Upgrade operations go here. Don't create your own engine;
    # bind migrate_engine to your metadata

    if migrate_engine.name != 'mysql':
        # InnoDB / MyISAM only applies to MySQL.
        return

    # This is a list of all the tables that might have been created with MyISAM
    # rather than InnoDB.
    tables = [
        'credential',
        'domain',
        'ec2_credential',
        'endpoint',
        'group',
        'group_domain_metadata',
        'group_project_metadata',
        'policy',
        'project',
        'role',
        'service',
        'token',
        'trust',
        'trust_role',
        'user',
        'user_domain_metadata',
        'user_group_membership',
        'user_project_metadata',
    ]

    meta = MetaData()
    meta.bind = migrate_engine

    domain_table = sql.Table('domain', meta, autoload=True)
    endpoint_table = sql.Table('endpoint', meta, autoload=True)
    group_table = sql.Table('group', meta, autoload=True)
    group_domain_metadata_table = sql.Table('group_domain_metadata', meta,
                                            autoload=True)
    group_project_metadata_table = sql.Table('group_project_metadata', meta,
                                             autoload=True)
    project_table = sql.Table('project', meta, autoload=True)
    service_table = sql.Table('service', meta, autoload=True)
    user_table = sql.Table('user', meta, autoload=True)
    user_domain_metadata_table = sql.Table('user_domain_metadata', meta,
                                           autoload=True)
    user_group_membership_table = sql.Table('user_group_membership', meta,
                                            autoload=True)

    # Mapping of table name to the constraints on that table,
    # so we can create them.
    table_constraints = {
        'endpoint': [{'table': endpoint_table,
                      'fk_column': 'service_id',
                      'ref_column': service_table.c.id},
                     ],
        'group': [{'table': group_table,
                   'fk_column': 'domain_id',
                   'ref_column': domain_table.c.id},
                  ],
        'group_domain_metadata': [{'table': group_domain_metadata_table,
                                   'fk_column': 'domain_id',
                                   'ref_column': domain_table.c.id},
                                  ],
        'group_project_metadata': [{'table': group_project_metadata_table,
                                    'fk_column': 'project_id',
                                    'ref_column': project_table.c.id},
                                   ],
        'project': [{'table': project_table,
                     'fk_column': 'domain_id',
                     'ref_column': domain_table.c.id},
                    ],
        'user': [{'table': user_table,
                  'fk_column': 'domain_id',
                  'ref_column': domain_table.c.id},
                 ],
        'user_domain_metadata': [{'table': user_domain_metadata_table,
                                  'fk_column': 'domain_id',
                                  'ref_column': domain_table.c.id},
                                 ],
        'user_group_membership': [{'table': user_group_membership_table,
                                   'fk_column': 'user_id',
                                   'ref_column': user_table.c.id},
                                  {'table': user_group_membership_table,
                                   'fk_column': 'group_id',
                                   'ref_column': group_table.c.id},
                                  ],
        'user_project_metadata': [{'table': group_project_metadata_table,
                                   'fk_column': 'project_id',
                                   'ref_column': project_table.c.id},
                                  ],
    }

    # Maps a table name to the tables that reference it as a FK constraint
    # (See the map above).
    ref_tables_map = {
        'service': ['endpoint', ],
        'domain': ['group', 'group_domain_metadata', 'project', 'user',
                   'user_domain_metadata', ],
        'project': ['group_project_metadata', 'user_project_metadata', ],
        'user': ['user_group_membership', ],
        'group': ['user_group_membership', ],
    }

    # The names of tables that need to have their FKs added.
    fk_table_names = set()

    d = migrate_engine.execute("SHOW TABLE STATUS WHERE Engine!='InnoDB';")
    for row in d.fetchall():
        table_name = row[0]

        if table_name not in tables:
            # Skip this table since it's not a Keystone table.
            continue

        migrate_engine.execute("ALTER TABLE `%s` Engine=InnoDB" % table_name)

        # Will add the FKs to the table if any of
        # a) the table itself was converted
        # b) the tables that the table referenced were converted

        if table_name in table_constraints:
            fk_table_names.add(table_name)

        ref_tables = ref_tables_map.get(table_name, [])
        for other_table_name in ref_tables:
            fk_table_names.add(other_table_name)

    # Now add all the FK constraints to those tables
    for table_name in fk_table_names:
        constraints = table_constraints.get(table_name)
        migration_helpers.add_constraints(constraints)