**** CubicPower OpenStack Study ****
def downgrade_token_table_with_column_drop(meta, migrate_engine):
token_table = sqlalchemy.Table('token', meta, autoload=True)
#delete old tokens, as the format has changed.
#We don't guarantee that existing tokens will be
#usable after a migration
token_table.delete()
token_table.drop_column(
sqlalchemy.Column('trust_id',
sqlalchemy.String(64),
nullable=True))
token_table.drop_column(
sqlalchemy.Column('user_id',
sqlalchemy.String(64)))
**** CubicPower OpenStack Study ****
def create_column_forgiving(migrate_engine, table, column):
try:
table.create_column(column)
except exc.OperationalError as e:
if (e.args[0].endswith('duplicate column name: %s' % column.name)
and migrate_engine.name == "sqlite"):
#sqlite does not drop columns, so if we have already
#done a downgrade and are now upgrading, we will hit
#this: the SQLite driver previously reported success
#dropping the columns but it hasn't.
pass
else:
raise
**** CubicPower OpenStack Study ****
def upgrade_token_table(meta, migrate_engine):
#delete old tokens, as the format has changed.
#The existing tokens will not
#support some of the list functions
token_table = sqlalchemy.Table('token', meta, autoload=True)
token_table.delete()
create_column_forgiving(
migrate_engine, token_table,
sqlalchemy.Column('trust_id',
sqlalchemy.String(64),
nullable=True))
create_column_forgiving(
migrate_engine, token_table,
sqlalchemy.Column('user_id', sqlalchemy.String(64)))
**** CubicPower OpenStack Study ****
def upgrade(migrate_engine):
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
upgrade_token_table(meta, migrate_engine)
**** CubicPower OpenStack Study ****
def downgrade(migrate_engine):
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
downgrade_token_table_with_column_drop(meta, migrate_engine)