¡@

Home 

OpenStack Study: 010_add_transfers_table.py

OpenStack Index

**** CubicPower OpenStack Study ****

def upgrade(migrate_engine):

    meta = MetaData()

    meta.bind = migrate_engine

    volumes = Table('volumes', meta, autoload=True)

    # New table

    transfers = Table(

        'transfers', meta,

        Column('created_at', DateTime(timezone=False)),

        Column('updated_at', DateTime(timezone=False)),

        Column('deleted_at', DateTime(timezone=False)),

        Column('deleted', Boolean),

        Column('id', String(36), primary_key=True, nullable=False),

        Column('volume_id', String(length=36), ForeignKey('volumes.id'),

               nullable=False),

        Column('display_name', String(length=255)),

        Column('salt', String(length=255)),

        Column('crypt_hash', String(length=255)),

        Column('expires_at', DateTime(timezone=False)),

        mysql_engine='InnoDB',

        mysql_charset='utf8'

    )

    try:

        transfers.create()

    except Exception:

        LOG.error(_("Table |%s| not created!"), repr(transfers))

        raise

**** CubicPower OpenStack Study ****

def downgrade(migrate_engine):

    meta = MetaData()

    meta.bind = migrate_engine

    transfers = Table('transfers',

                      meta,

                      autoload=True)

    try:

        transfers.drop()

    except Exception:

        LOG.error(_("transfers table not dropped"))

        raise