**** CubicPower OpenStack Study ****
def downgrade_user_table_with_copy(meta, migrate_engine):
maker = sessionmaker(bind=migrate_engine)
session = maker()
session.execute("ALTER TABLE user RENAME TO orig_user;")
user_table = Table(
'user',
meta,
Column('id', String(64), primary_key=True),
Column('name', String(64), unique=True, nullable=False),
Column('extra', Text()))
user_table.create(migrate_engine, checkfirst=True)
orig_user_table = Table('orig_user', meta, autoload=True)
for user in session.query(orig_user_table):
session.execute("insert into user (id, name, extra) "
"values ( :id, :name, :extra);",
{'id': user.id,
'name': user.name,
'extra': user.extra})
session.execute("drop table orig_user;")
session.close()
**** CubicPower OpenStack Study ****
def downgrade_tenant_table_with_copy(meta, migrate_engine):
maker = sessionmaker(bind=migrate_engine)
session = maker()
session.execute("ALTER TABLE tenant RENAME TO orig_tenant;")
tenant_table = Table(
'tenant',
meta,
Column('id', String(64), primary_key=True),
Column('name', String(64), unique=True, nullable=False),
Column('extra', Text()))
tenant_table.create(migrate_engine, checkfirst=True)
orig_tenant_table = Table('orig_tenant', meta, autoload=True)
for tenant in session.query(orig_tenant_table):
session.execute("insert into tenant (id, name, extra) "
"values ( :id, :name, :extra);",
{'id': tenant.id,
'name': tenant.name,
'extra': tenant.extra})
session.execute("drop table orig_tenant;")
session.close()
**** CubicPower OpenStack Study ****
def downgrade_user_table_with_column_drop(meta, migrate_engine):
user_table = Table('user', meta, autoload=True)
user_table.drop_column(Column('password', String(128)))
user_table.drop_column(Column('enabled', types.Boolean,
default=True))
**** CubicPower OpenStack Study ****
def downgrade_tenant_table_with_column_drop(meta, migrate_engine):
tenant_table = Table('tenant', meta, autoload=True)
tenant_table.drop_column(Column('description', Text()))
tenant_table.drop_column(Column('enabled', types.Boolean))
**** CubicPower OpenStack Study ****
def upgrade_user_table(meta, migrate_engine):
user_table = Table('user', meta, autoload=True)
user_table.create_column(Column('password', String(128)))
user_table.create_column(Column('enabled', types.Boolean,
default=True))
**** CubicPower OpenStack Study ****
def upgrade_tenant_table(meta, migrate_engine):
tenant_table = Table('tenant', meta, autoload=True)
tenant_table.create_column(Column('description', Text()))
tenant_table.create_column(Column('enabled', types.Boolean))
**** CubicPower OpenStack Study ****
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
upgrade_user_table(meta, migrate_engine)
upgrade_tenant_table(meta, migrate_engine)
**** CubicPower OpenStack Study ****
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
if migrate_engine.name == 'sqlite':
downgrade_user_table_with_copy(meta, migrate_engine)
downgrade_tenant_table_with_copy(meta, migrate_engine)
else:
downgrade_user_table_with_column_drop(meta, migrate_engine)
downgrade_tenant_table_with_column_drop(meta, migrate_engine)