¡@

Home 

OpenStack Study: 010_add_preserve_ephemeral.py

OpenStack Index

**** CubicPower OpenStack Study ****

def upgrade(migrate_engine):

    meta = MetaData()

    meta.bind = migrate_engine

    t = Table(TABLE_NAME, meta, autoload=True)

    default = text('0') if migrate_engine.name == 'sqlite' else text('false')

    preserve_ephemeral_col = Column(COLUMN_NAME, Boolean,

                                    server_default=default)

    t.create_column(preserve_ephemeral_col)

**** CubicPower OpenStack Study ****

def downgrade(migrate_engine):

    meta = MetaData()

    meta.bind = migrate_engine

    t = Table(TABLE_NAME, meta, autoload=True)

    # NOTE(rpodolyaka): SQLite doesn't have native BOOLEAN type, so it's

    #                   emulated by adding a CHECK constraint. We must

    #                   explicitly omit that constraint here so we don't

    #                   receive 'no such column' error when dropping the

    #                   column

    if migrate_engine.name == 'sqlite':

        t.constraints = set([

            c

            for c in t.constraints

            if not (hasattr(c, 'sqltext') and COLUMN_NAME in str(c.sqltext))

        ])

    t.drop_column(COLUMN_NAME)