Merge "Remove downgrade support from migrations"
This commit is contained in:
commit
4fe84bcaf7
@ -36,9 +36,6 @@ class DBCommand(object):
|
||||
def upgrade(self):
|
||||
migration.upgrade(CONF.command.revision)
|
||||
|
||||
def downgrade(self):
|
||||
migration.downgrade(CONF.command.revision)
|
||||
|
||||
def revision(self):
|
||||
migration.revision(CONF.command.message, CONF.command.autogenerate)
|
||||
|
||||
@ -63,14 +60,6 @@ def add_command_parsers(subparsers):
|
||||
parser.set_defaults(func=command_object.upgrade)
|
||||
parser.add_argument('--revision', nargs='?')
|
||||
|
||||
parser = subparsers.add_parser(
|
||||
'downgrade',
|
||||
help=_("Downgrade the database schema to the oldest revision. "
|
||||
"While optional, one should generally use --revision to "
|
||||
"specify the alembic revision string to downgrade to."))
|
||||
parser.set_defaults(func=command_object.downgrade)
|
||||
parser.add_argument('--revision', nargs='?')
|
||||
|
||||
parser = subparsers.add_parser('stamp')
|
||||
parser.add_argument('--revision', nargs='?')
|
||||
parser.set_defaults(func=command_object.stamp)
|
||||
|
@ -36,10 +36,6 @@ def upgrade(version=None):
|
||||
return get_backend().upgrade(version)
|
||||
|
||||
|
||||
def downgrade(version=None):
|
||||
return get_backend().downgrade(version)
|
||||
|
||||
|
||||
def version():
|
||||
return get_backend().version()
|
||||
|
||||
|
@ -33,8 +33,3 @@ def upgrade():
|
||||
op.add_column('nodes', sa.Column('inspection_finished_at',
|
||||
sa.DateTime(),
|
||||
nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('nodes', 'inspection_started_at')
|
||||
op.drop_column('nodes', 'inspection_finished_at')
|
||||
|
@ -29,7 +29,3 @@ import sqlalchemy as sa
|
||||
def upgrade():
|
||||
op.add_column('nodes', sa.Column('provision_updated_at', sa.DateTime(),
|
||||
nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('nodes', 'provision_updated_at')
|
||||
|
@ -30,7 +30,3 @@ def upgrade():
|
||||
op.add_column('nodes', sa.Column('maintenance_reason',
|
||||
sa.Text(),
|
||||
nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('nodes', 'maintenance_reason')
|
||||
|
@ -99,8 +99,3 @@ def upgrade():
|
||||
mysql_DEFAULT_CHARSET='UTF8'
|
||||
)
|
||||
# end Alembic commands
|
||||
|
||||
|
||||
def downgrade():
|
||||
raise NotImplementedError(('Downgrade from initial migration is'
|
||||
' unsupported.'))
|
||||
|
@ -33,10 +33,3 @@ def upgrade():
|
||||
existing_type=mysql.VARCHAR(length=63),
|
||||
type_=sa.String(length=255),
|
||||
existing_nullable=True)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.alter_column('nodes', 'name',
|
||||
existing_type=sa.String(length=255),
|
||||
type_=mysql.VARCHAR(length=63),
|
||||
existing_nullable=True)
|
||||
|
@ -32,9 +32,3 @@ def upgrade():
|
||||
sa.Text(),
|
||||
nullable=True))
|
||||
# end Alembic commands
|
||||
|
||||
|
||||
def downgrade():
|
||||
# commands auto generated by Alembic - please adjust
|
||||
op.drop_column('nodes', 'instance_info')
|
||||
# end Alembic commands
|
||||
|
@ -30,8 +30,3 @@ def upgrade():
|
||||
op.add_column('nodes', sa.Column('name', sa.String(length=63),
|
||||
nullable=True))
|
||||
op.create_unique_constraint('uniq_nodes0name', 'nodes', ['name'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_constraint('uniq_nodes0name', 'nodes', type_='unique')
|
||||
op.drop_column('nodes', 'name')
|
||||
|
@ -32,8 +32,3 @@ def upgrade():
|
||||
op.create_unique_constraint("uniq_nodes0instance_uuid", "nodes",
|
||||
["instance_uuid"])
|
||||
op.drop_index('node_instance_uuid', 'nodes')
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_constraint("uniq_nodes0instance_uuid", "nodes", type_='unique')
|
||||
op.create_index('node_instance_uuid', 'nodes', ['instance_uuid'])
|
||||
|
@ -28,7 +28,3 @@ import sqlalchemy as sa
|
||||
|
||||
def upgrade():
|
||||
op.add_column('nodes', sa.Column('console_enabled', sa.Boolean))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('nodes', 'console_enabled')
|
||||
|
@ -36,10 +36,3 @@ def upgrade():
|
||||
sa.ForeignKey('conductors.id',
|
||||
name='nodes_conductor_affinity_fk'),
|
||||
nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_constraint('nodes_conductor_affinity_fk', 'nodes',
|
||||
type_='foreignkey')
|
||||
op.drop_column('nodes', 'conductor_affinity')
|
||||
op.drop_column('conductors', 'online')
|
||||
|
@ -40,7 +40,3 @@ def upgrade():
|
||||
mysql_DEFAULT_CHARSET='UTF8'
|
||||
)
|
||||
op.create_index('node_tags_idx', 'node_tags', ['tag'], unique=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('node_tags')
|
||||
|
@ -29,7 +29,3 @@ import sqlalchemy as sa
|
||||
def upgrade():
|
||||
op.add_column('nodes', sa.Column('clean_step', sa.Text(),
|
||||
nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('nodes', 'clean_step')
|
||||
|
@ -30,7 +30,3 @@ def upgrade():
|
||||
op.alter_column('nodes', 'driver',
|
||||
existing_type=sa.String(length=15),
|
||||
type_=sa.String(length=255))
|
||||
|
||||
|
||||
def downgrade():
|
||||
pass
|
||||
|
@ -43,10 +43,3 @@ def upgrade():
|
||||
node.update().where(
|
||||
node.c.provision_state == null()).values(
|
||||
{'provision_state': op.inline_literal(AVAILABLE)}))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.execute(
|
||||
node.update().where(
|
||||
node.c.provision_state == op.inline_literal(AVAILABLE)).values(
|
||||
{'provision_state': None}))
|
||||
|
@ -31,8 +31,3 @@ def upgrade():
|
||||
nullable=True))
|
||||
op.add_column('nodes', sa.Column('target_raid_config', sa.Text(),
|
||||
nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('nodes', 'raid_config')
|
||||
op.drop_column('nodes', 'target_raid_config')
|
||||
|
@ -30,7 +30,3 @@ def upgrade():
|
||||
op.add_column('nodes', sa.Column('driver_internal_info',
|
||||
sa.Text(),
|
||||
nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('nodes', 'driver_internal_info')
|
||||
|
@ -98,7 +98,7 @@ def patch_with_engine(engine):
|
||||
|
||||
|
||||
class WalkVersionsMixin(object):
|
||||
def _walk_versions(self, engine=None, alembic_cfg=None, downgrade=True):
|
||||
def _walk_versions(self, engine=None, alembic_cfg=None):
|
||||
# Determine latest version script from the repo, then
|
||||
# upgrade from 1 through to the latest, with no data
|
||||
# in the databases. This just checks that the schema itself
|
||||
@ -117,31 +117,6 @@ class WalkVersionsMixin(object):
|
||||
self._migrate_up(engine, alembic_cfg,
|
||||
version.revision, with_data=True)
|
||||
|
||||
if downgrade:
|
||||
for version in versions:
|
||||
self._migrate_down(engine, alembic_cfg, version.revision)
|
||||
|
||||
def _migrate_down(self, engine, config, version, with_data=False):
|
||||
try:
|
||||
self.migration_api.downgrade(version, config=config)
|
||||
except NotImplementedError:
|
||||
# NOTE(sirp): some migrations, namely release-level
|
||||
# migrations, don't support a downgrade.
|
||||
return False
|
||||
|
||||
self.assertEqual(version, self.migration_api.version(config))
|
||||
|
||||
# NOTE(sirp): `version` is what we're downgrading to (i.e. the 'target'
|
||||
# version). So if we have any downgrade checks, they need to be run for
|
||||
# the previous (higher numbered) migration.
|
||||
if with_data:
|
||||
post_downgrade = getattr(
|
||||
self, "_post_downgrade_%s" % (version), None)
|
||||
if post_downgrade:
|
||||
post_downgrade(engine)
|
||||
|
||||
return True
|
||||
|
||||
def _migrate_up(self, engine, config, version, with_data=False):
|
||||
"""migrate up to a new version of the db.
|
||||
|
||||
@ -201,29 +176,9 @@ class TestWalkVersions(base.TestCase, WalkVersionsMixin):
|
||||
self._pre_upgrade_141.assert_called_with(self.engine)
|
||||
self._check_141.assert_called_with(self.engine, test_value)
|
||||
|
||||
def test_migrate_down(self):
|
||||
self.migration_api.version.return_value = '42'
|
||||
|
||||
self.assertTrue(self._migrate_down(self.engine, self.config, '42'))
|
||||
self.migration_api.version.assert_called_with(self.config)
|
||||
|
||||
def test_migrate_down_not_implemented(self):
|
||||
self.migration_api.downgrade.side_effect = NotImplementedError
|
||||
self.assertFalse(self._migrate_down(self.engine, self.config, '42'))
|
||||
|
||||
def test_migrate_down_with_data(self):
|
||||
self._post_downgrade_043 = mock.MagicMock()
|
||||
self.migration_api.version.return_value = '043'
|
||||
|
||||
self._migrate_down(self.engine, self.config, '043', True)
|
||||
|
||||
self._post_downgrade_043.assert_called_with(self.engine)
|
||||
|
||||
@mock.patch.object(script, 'ScriptDirectory')
|
||||
@mock.patch.object(WalkVersionsMixin, '_migrate_up')
|
||||
@mock.patch.object(WalkVersionsMixin, '_migrate_down')
|
||||
def test_walk_versions_all_default(self, _migrate_up, _migrate_down,
|
||||
script_directory):
|
||||
def test_walk_versions_all_default(self, _migrate_up, script_directory):
|
||||
fc = script_directory.from_config()
|
||||
fc.walk_revisions.return_value = self.versions
|
||||
self.migration_api.version.return_value = None
|
||||
@ -236,20 +191,14 @@ class TestWalkVersions(base.TestCase, WalkVersionsMixin):
|
||||
with_data=True) for v in reversed(self.versions)]
|
||||
self.assertEqual(self._migrate_up.call_args_list, upgraded)
|
||||
|
||||
downgraded = [mock.call(self.engine, self.config, v.revision)
|
||||
for v in self.versions]
|
||||
self.assertEqual(self._migrate_down.call_args_list, downgraded)
|
||||
|
||||
@mock.patch.object(script, 'ScriptDirectory')
|
||||
@mock.patch.object(WalkVersionsMixin, '_migrate_up')
|
||||
@mock.patch.object(WalkVersionsMixin, '_migrate_down')
|
||||
def test_walk_versions_all_false(self, _migrate_up, _migrate_down,
|
||||
script_directory):
|
||||
def test_walk_versions_all_false(self, _migrate_up, script_directory):
|
||||
fc = script_directory.from_config()
|
||||
fc.walk_revisions.return_value = self.versions
|
||||
self.migration_api.version.return_value = None
|
||||
|
||||
self._walk_versions(self.engine, self.config, downgrade=False)
|
||||
self._walk_versions(self.engine, self.config)
|
||||
|
||||
upgraded = [mock.call(self.engine, self.config, v.revision,
|
||||
with_data=True) for v in reversed(self.versions)]
|
||||
@ -264,7 +213,7 @@ class MigrationCheckersMixin(object):
|
||||
self.migration_api = migration
|
||||
|
||||
def test_walk_versions(self):
|
||||
self._walk_versions(self.engine, self.config, downgrade=False)
|
||||
self._walk_versions(self.engine, self.config)
|
||||
|
||||
def test_connect_fail(self):
|
||||
"""Test that we can trigger a database connection failure
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- Database migrations downgrade support was removed. More info about
|
||||
database migration/rollback could be found here
|
||||
http://docs.openstack.org/openstack-ops/content/ops_upgrades-roll-back.html
|
Loading…
Reference in New Issue
Block a user