Fix downgrades in migration scripts 016 and 035

Downgrade behavior was not checked in Heat, so there are a few mistakes
in migration scripts. Fixed these scripts, set test attributes
`snake_walk` and `downgrade` to True due to allow migration testing and
avoid of regression.

Change-Id: I30cfb282cf7884d8b2748c6486a68d05072957af
This commit is contained in:
Victor Sergeyev 2014-07-28 14:22:00 +03:00
parent 848bc37e2a
commit dd60cca79b
4 changed files with 43 additions and 5 deletions

View File

@ -27,4 +27,7 @@ def downgrade(migrate_engine):
meta.bind = migrate_engine
stack = sqlalchemy.Table('stack', meta, autoload=True)
# NOTE(viktors): We must be sure, that there are no nullable columns in
# `stack` table before we alter it.
migrate_engine.execute('UPDATE stack set timeout=60 WHERE timeout IS NULL')
stack.c.timeout.alter(nullable=False)

View File

@ -146,6 +146,9 @@ def downgrade(migrate_engine):
cons.create()
event_table.c.tmp_id.alter('id', default=lambda: str(uuid.uuid4))
if migrate_engine.name == 'postgresql':
sequence = sqlalchemy.Sequence('evt')
sqlalchemy.schema.DropSequence(sequence, bind=migrate_engine).execute()
def downgrade_sqlite(migrate_engine):
@ -178,7 +181,7 @@ def downgrade_sqlite(migrate_engine):
event_table.create()
prev_event_table = sqlalchemy.Table('event', meta, autoload=True)
event_list = prev_event_table.select().execute()
event_list = prev_event_table.select().execute().fetchall()
for event in event_list:
values = {
'id': event.uuid,

View File

@ -39,4 +39,36 @@ def downgrade(migrate_engine):
meta = sqlalchemy.MetaData(bind=migrate_engine)
stack = sqlalchemy.Table('stack', meta, autoload=True)
if migrate_engine.name == 'sqlite':
_downgrade_045_sqlite(migrate_engine, meta, stack)
else:
stack.c.backup.drop()
def _downgrade_045_sqlite(migrate_engine, metadata, table):
table_name = table.name
constraints = [
c.copy() for c in table.constraints
if not isinstance(c, sqlalchemy.CheckConstraint)
]
columns = [c.copy() for c in table.columns if c.name != "backup"]
new_table = sqlalchemy.Table(table_name + "__tmp__", metadata,
*(columns + constraints))
new_table.create()
migrate_data = """
INSERT INTO stack__tmp__
SELECT id, created_at, updated_at, name, raw_template_id,
user_creds_id, username, owner_id, status, status_reason,
parameters, timeout, tenant, disable_rollback, action,
deleted_at, stack_user_project_id
FROM stack;"""
migrate_engine.execute(migrate_data)
table.drop()
new_table.rename(table_name)

View File

@ -39,8 +39,8 @@ class HeatMigrationsCheckers(test_migrations.WalkVersionsMixin,
common.FakeLogMixin):
"""Test sqlalchemy-migrate migrations."""
snake_walk = False
downgrade = False
snake_walk = True
downgrade = True
@property
def INIT_VERSION(self):
@ -206,7 +206,7 @@ class HeatMigrationsCheckers(test_migrations.WalkVersionsMixin,
def _pre_upgrade_045(self, engine):
raw_template = utils.get_table(engine, 'raw_template')
templ = [dict(id=5, template='{}')]
templ = [dict(id=5, template='{}', files='{}')]
engine.execute(raw_template.insert(), templ)
user_creds = utils.get_table(engine, 'user_creds')