¡@

Home 

OpenStack Study: 008_add_backup.py

OpenStack Index

**** CubicPower OpenStack Study ****

def upgrade(migrate_engine):

    meta = MetaData()

    meta.bind = migrate_engine

    # New table

    backups = Table(

        'backups', meta,

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

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

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

        Column('deleted', Boolean(create_constraint=True, name=None)),

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

        Column('volume_id', String(36), nullable=False),

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

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

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

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

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

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

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

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

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

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

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

        Column('size', Integer()),

        Column('object_count', Integer()),

        mysql_engine='InnoDB'

    )

    try:

        backups.create()

    except Exception:

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

        raise

**** CubicPower OpenStack Study ****

def downgrade(migrate_engine):

    meta = MetaData()

    meta.bind = migrate_engine

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

    try:

        backups.drop()

    except Exception:

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

        raise