¡@

Home 

OpenStack Study: 026_drop_user_group_constraints.py

OpenStack Index

**** CubicPower OpenStack Study ****

def list_constraints(migrate_engine):

    meta = sqlalchemy.MetaData()

    meta.bind = migrate_engine

    user_table = sqlalchemy.Table('user', meta, autoload=True)

    sqlalchemy.Table('project', meta, autoload=True)

    group_table = sqlalchemy.Table('group', meta, autoload=True)

    user_domain_metadata_table = sqlalchemy.Table('user_domain_metadata',

                                                  meta, autoload=True)

    group_domain_metadata_table = sqlalchemy.Table('group_domain_metadata',

                                                   meta, autoload=True)

    user_project_metadata_table = sqlalchemy.Table('user_project_metadata',

                                                   meta, autoload=True)

    group_project_metadata_table = sqlalchemy.Table('group_project_metadata',

                                                    meta, autoload=True)

    constraints = [{'table': user_domain_metadata_table,

                    'fk_column': 'user_id',

                    'ref_column': user_table.c.id},

                   {'table': group_domain_metadata_table,

                    'fk_column': 'group_id',

                    'ref_column': group_table.c.id},

                   {'table': user_project_metadata_table,

                    'fk_column': 'user_id',

                    'ref_column': user_table.c.id},

                   {'table': group_project_metadata_table,

                    'fk_column': 'group_id',

                    'ref_column': group_table.c.id},

                   ]

    return constraints

**** CubicPower OpenStack Study ****

def upgrade(migrate_engine):

    if migrate_engine.name == 'sqlite':

        return

    migration_helpers.remove_constraints(list_constraints(migrate_engine))

**** CubicPower OpenStack Study ****

def downgrade(migrate_engine):

    if migrate_engine.name == 'sqlite':

        return

    migration_helpers.add_constraints(list_constraints(migrate_engine))