Exemple #1
0
def downgrade(migrate_engine):
    meta = sql.MetaData()
    meta.bind = migrate_engine

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

    ec2_credential_table = sql.Table('ec2_credential',
                                     meta,
                                     sql.Column('access',
                                                sql.String(64),
                                                primary_key=True),
                                     sql.Column('secret', sql.String(64)),
                                     sql.Column('user_id', sql.String(64)),
                                     sql.Column('tenant_id', sql.String(64)),
                                     mysql_engine='InnoDB',
                                     mysql_charset='utf8')

    ec2_credential_table.create(migrate_engine, checkfirst=True)
    credential_table = sql.Table('credential', meta, autoload=True)
    insert = ec2_credential_table.insert()
    for credential in session.query(credential_table).filter(
            sql.and_(credential_table.c.type == 'ec2',
                     credential_table.c.project_id is not None)).all():
        ec2_credential = utils.convert_v3_to_ec2_credential(credential)
        insert.execute(ec2_credential)

    session.commit()
    session.close()
def downgrade(migrate_engine):
    meta = sql.MetaData()
    meta.bind = migrate_engine

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

    ec2_credential_table = sql.Table(
        'ec2_credential',
        meta,
        sql.Column('access', sql.String(64), primary_key=True),
        sql.Column('secret', sql.String(64)),
        sql.Column('user_id', sql.String(64)),
        sql.Column('tenant_id', sql.String(64)),
        mysql_engine='InnoDB',
        mysql_charset='utf8')

    ec2_credential_table.create(migrate_engine, checkfirst=True)
    credential_table = sql.Table('credential',
                                 meta,
                                 autoload=True)
    insert = ec2_credential_table.insert()
    for credential in session.query(credential_table).filter(
            sql.and_(credential_table.c.type == 'ec2',
                     credential_table.c.project_id is not None)).all():
        ec2_credential = utils.convert_v3_to_ec2_credential(credential)
        insert.execute(ec2_credential)

    session.commit()
    session.close()