Removes downgrade from db migration scripts

downgrade is not to be supported from kilo release
onwards and is good to clean up the code.

Closes-bug: #1668887

Change-Id: I4b3f264d8691b74d602df466752eccbea533c209
This commit is contained in:
Kanagaraj Manickam 2017-03-01 12:50:50 +05:30
parent 868bc0d971
commit 3ca19f068e
12 changed files with 11 additions and 163 deletions

View File

@ -16,7 +16,7 @@
The migrations in the alembic/versions contain the changes needed to migrate
from older Tacker releases to newer versions. A migration occurs by executing
a script that details the changes needed to upgrade/downgrade the database. The
a script that details the changes needed to upgrade the database. The
migration scripts are ordered so that multiple scripts can run sequentially to
update the database. The scripts are executed by Tacker's migration wrapper
which uses the Alembic library to manage the migration. Tacker supports
@ -50,15 +50,11 @@ Upgrade the database incrementally:
$ tacker-db-manage --config-file /path/to/tacker.conf \
--config-file /path/to/plugin/config.ini upgrade --delta <# of revs>
Downgrade the database by a certain number of revisions:
$ tacker-db-manage --config-file /path/to/tacker.conf \
--config-file /path/to/plugin/config.ini downgrade --delta <# of revs>
DEVELOPERS:
A database migration script is required when you submit a change to Tacker
that alters the database model definition. The migration script is a special
python file that includes code to update/downgrade the database to match the
python file that includes code to upgrade the database to match the
changes in the model definition. Alembic will execute these scripts in order to
provide a linear migration path between revision. The tacker-db-manage command
can be used to generate migration template for you to complete. The operations
@ -74,7 +70,7 @@ database state with the models. You should inspect the autogenerated template
to ensure that the proper models have been altered.
In rare circumstances, you may want to start with an empty migration template
and manually author the changes necessary for an upgrade/downgrade. You can
and manually author the changes necessary for an upgrade. You can
create a blank file via:
$ tacker-db-manage --config-file /path/to/tacker.conf \
@ -82,8 +78,7 @@ $ tacker-db-manage --config-file /path/to/tacker.conf \
-m "description of revision"
The migration timeline should remain linear so that there is a clear path when
upgrading/downgrading. To verify that the timeline does branch, you can run
this command:
upgrading. To verify that the timeline does branch, you can run this command:
$ tacker-db-manage --config-file /path/to/tacker.conf \
--config-file /path/to/plugin/config.ini check_migration

View File

@ -34,7 +34,3 @@ from tacker.db import migration
def upgrade(active_plugins=None, options=None):
${upgrades if upgrades else "pass"}
def downgrade(active_plugins=None, options=None):
${downgrades if downgrades else "pass"}

View File

@ -96,13 +96,3 @@ def upgrade(active_plugins=None, options=None):
mysql_engine='InnoDB'
)
# end Alembic commands #
def downgrade(active_plugins=None, options=None):
# commands auto generated by Alembic - please adjust! #
op.drop_table('servicedevicebindings')
op.drop_table('servicecontexts')
op.drop_table('serviceinstances')
op.drop_table('deviceservicecontexts')
op.drop_table('servicetypes')
# end Alembic commands #

View File

@ -40,14 +40,3 @@ def upgrade(active_plugins=None, options=None):
op.alter_column(u'devices', 'status', existing_type=mysql.VARCHAR(
length=255), nullable=False)
# end Alembic commands #s
def downgrade(active_plugins=None, options=None):
# commands auto generated by Alembic - please adjust! #
op.alter_column(u'devices', 'status',
existing_type=mysql.VARCHAR(length=255),
nullable=True)
op.alter_column(u'deviceattributes', 'device_id',
existing_type=mysql.VARCHAR(length=255),
nullable=True)
# end Alembic commands #

View File

@ -33,7 +33,3 @@ def upgrade(active_plugins=None, options=None):
op.drop_table('proxymgmtports')
op.drop_table('proxyserviceports')
# end Alembic commands #
def downgrade(active_plugins=None, options=None):
pass

View File

@ -26,8 +26,6 @@ revision = '2774a42c7163'
down_revision = '12a57080b278'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
def upgrade(active_plugins=None, options=None):
@ -37,79 +35,3 @@ def upgrade(active_plugins=None, options=None):
op.drop_table('servicedevicebindings')
op.drop_table('serviceinstances')
# end Alembic commands #
def downgrade(active_plugins=None, options=None):
# commands auto generated by Alembic - please adjust! #
op.create_table(
'deviceservicecontexts',
sa.Column('id', mysql.VARCHAR(length=36), nullable=False),
sa.Column('device_id', mysql.VARCHAR(length=36), nullable=True),
sa.Column('network_id', mysql.VARCHAR(length=36), nullable=True),
sa.Column('subnet_id', mysql.VARCHAR(length=36), nullable=True),
sa.Column('port_id', mysql.VARCHAR(length=36), nullable=True),
sa.Column('router_id', mysql.VARCHAR(length=36), nullable=True),
sa.Column('role', mysql.VARCHAR(length=255), nullable=True),
sa.Column('index', mysql.INTEGER(display_width=11),
autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['device_id'], [u'devices.id'],
name=u'deviceservicecontexts_ibfk_1'),
sa.PrimaryKeyConstraint('id'),
mysql_default_charset=u'utf8',
mysql_engine=u'InnoDB'
)
op.create_table(
'serviceinstances',
sa.Column('tenant_id', mysql.VARCHAR(length=255), nullable=True),
sa.Column('id', mysql.VARCHAR(length=36), nullable=False),
sa.Column('name', mysql.VARCHAR(length=255), nullable=True),
sa.Column('service_type_id', mysql.VARCHAR(length=36), nullable=True),
sa.Column('service_table_id', mysql.VARCHAR(length=36), nullable=True),
sa.Column('managed_by_user', mysql.TINYINT(display_width=1),
autoincrement=False, nullable=True),
sa.Column('mgmt_driver', mysql.VARCHAR(length=255), nullable=True),
sa.Column('mgmt_url', mysql.VARCHAR(length=255), nullable=True),
sa.Column('status', mysql.VARCHAR(length=255), nullable=False),
sa.ForeignKeyConstraint(['service_type_id'], [u'servicetypes.id'],
name=u'serviceinstances_ibfk_1'),
sa.PrimaryKeyConstraint('id'),
mysql_default_charset=u'utf8',
mysql_engine=u'InnoDB'
)
op.create_table(
'servicedevicebindings',
sa.Column('service_instance_id', mysql.VARCHAR(length=36),
nullable=False),
sa.Column('device_id', mysql.VARCHAR(length=36), nullable=False),
sa.ForeignKeyConstraint(['device_id'], [u'devices.id'],
name=u'servicedevicebindings_ibfk_1'),
sa.ForeignKeyConstraint(['service_instance_id'],
[u'serviceinstances.id'],
name=u'servicedevicebindings_ibfk_2'),
sa.PrimaryKeyConstraint('service_instance_id', 'device_id'),
mysql_default_charset=u'utf8',
mysql_engine=u'InnoDB'
)
op.create_table(
'servicecontexts',
sa.Column('id', mysql.VARCHAR(length=36), nullable=False),
sa.Column('service_instance_id', mysql.VARCHAR(length=36),
nullable=True),
sa.Column('network_id', mysql.VARCHAR(length=36), nullable=True),
sa.Column('subnet_id', mysql.VARCHAR(length=36), nullable=True),
sa.Column('port_id', mysql.VARCHAR(length=36), nullable=True),
sa.Column('router_id', mysql.VARCHAR(length=36), nullable=True),
sa.Column('role', mysql.VARCHAR(length=255), nullable=True),
sa.Column('index', mysql.INTEGER(display_width=11),
autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['service_instance_id'],
[u'serviceinstances.id'],
name=u'servicecontexts_ibfk_1'),
sa.PrimaryKeyConstraint('id'),
mysql_default_charset=u'utf8',
mysql_engine=u'InnoDB'
)
# end Alembic commands #

View File

@ -58,11 +58,3 @@ def upgrade(active_plugins=None, options=None):
op.add_column(u'devices', sa.Column('vim_id', sa.String(length=36),
nullable=False))
op.create_foreign_key(None, 'devices', 'vims', ['vim_id'], ['id'])
def downgrade(active_plugins=None, options=None):
op.drop_constraint(None, 'devices', type_='foreignkey')
op.drop_column(u'devices', 'vim_id')
op.drop_column(u'devices', 'placement_attr')
op.drop_table('vimauths')
op.drop_table('vims')

View File

@ -26,14 +26,7 @@ revision = '8f7145914cb0'
down_revision = '0ae5b1ce3024'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
def upgrade(active_plugins=None, options=None):
op.drop_column('vnfd', 'infra_driver')
def downgrade(active_plugins=None, options=None):
op.add_column('vnfd', sa.Column('infra_driver', mysql.VARCHAR(length=255),
nullable=True))

View File

@ -32,7 +32,3 @@ import sqlalchemy as sa
def upgrade(active_plugins=None, options=None):
op.add_column('devices', sa.Column('error_reason',
sa.Text(), nullable=True))
def downgrade(active_plugins=None, options=None):
op.drop_column('devices', 'error_reason')

View File

@ -32,7 +32,3 @@ from tacker.db.types import Json
def upgrade(active_plugins=None, options=None):
op.add_column('vnffgs', sa.Column('attributes', Json))
def downgrade(active_plugins=None, options=None):
op.drop_column('vnffgs', 'attributes')

View File

@ -53,15 +53,14 @@ def do_check_migration(config, cmd):
validate_head_file(config)
def do_upgrade_downgrade(config, cmd):
def do_upgrade(config, cmd):
if not CONF.command.revision and not CONF.command.delta:
raise SystemExit(_('You must provide a revision or relative delta'))
revision = CONF.command.revision
if CONF.command.delta:
sign = '+' if CONF.command.name == 'upgrade' else '-'
revision = sign + str(CONF.command.delta)
revision = '+%s' % str(CONF.command.delta)
else:
revision = CONF.command.revision
@ -121,12 +120,11 @@ def add_command_parsers(subparsers):
parser = subparsers.add_parser('check_migration')
parser.set_defaults(func=do_check_migration)
for name in ['upgrade', 'downgrade']:
parser = subparsers.add_parser(name)
parser.add_argument('--delta', type=int)
parser.add_argument('--sql', action='store_true')
parser.add_argument('revision', nargs='?')
parser.set_defaults(func=do_upgrade_downgrade)
parser = subparsers.add_parser('upgrade')
parser.add_argument('--delta', type=int)
parser.add_argument('--sql', action='store_true')
parser.add_argument('revision', nargs='?')
parser.set_defaults(func=do_upgrade)
parser = subparsers.add_parser('stamp')
parser.add_argument('--sql', action='store_true')

View File

@ -108,21 +108,6 @@ class TestCli(base.BaseTestCase):
{'sql': False}
)
def test_downgrade(self):
self._main_test_helper(
['prog', 'downgrade', '--sql', 'folsom'],
'downgrade',
('folsom',),
{'sql': True}
)
self._main_test_helper(
['prog', 'downgrade', '--delta', '2'],
'downgrade',
('-2',),
{'sql': False}
)
def _test_validate_head_file_helper(self, heads, file_content=None):
with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
fc.return_value.get_heads.return_value = heads