diff --git a/tacker/db/migration/README b/tacker/db/migration/README index c5de07d95..3b4d08da1 100644 --- a/tacker/db/migration/README +++ b/tacker/db/migration/README @@ -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 diff --git a/tacker/db/migration/alembic_migrations/script.py.mako b/tacker/db/migration/alembic_migrations/script.py.mako index 239ecec73..2b4fe10f1 100644 --- a/tacker/db/migration/alembic_migrations/script.py.mako +++ b/tacker/db/migration/alembic_migrations/script.py.mako @@ -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"} diff --git a/tacker/db/migration/alembic_migrations/versions/12a57080b277_add_service_db.py b/tacker/db/migration/alembic_migrations/versions/12a57080b277_add_service_db.py index 50f815749..ddaf32ae5 100644 --- a/tacker/db/migration/alembic_migrations/versions/12a57080b277_add_service_db.py +++ b/tacker/db/migration/alembic_migrations/versions/12a57080b277_add_service_db.py @@ -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 # diff --git a/tacker/db/migration/alembic_migrations/versions/12a57080b278_alter_devices.py b/tacker/db/migration/alembic_migrations/versions/12a57080b278_alter_devices.py index 2d4e5e3be..731fdf481 100644 --- a/tacker/db/migration/alembic_migrations/versions/12a57080b278_alter_devices.py +++ b/tacker/db/migration/alembic_migrations/versions/12a57080b278_alter_devices.py @@ -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 # diff --git a/tacker/db/migration/alembic_migrations/versions/22f5385a3d4f_remove_proxydb.py b/tacker/db/migration/alembic_migrations/versions/22f5385a3d4f_remove_proxydb.py index d84cd0500..17bc8238a 100644 --- a/tacker/db/migration/alembic_migrations/versions/22f5385a3d4f_remove_proxydb.py +++ b/tacker/db/migration/alembic_migrations/versions/22f5385a3d4f_remove_proxydb.py @@ -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 diff --git a/tacker/db/migration/alembic_migrations/versions/2774a42c7163_remove_service_related.py b/tacker/db/migration/alembic_migrations/versions/2774a42c7163_remove_service_related.py index 58ed85d5a..047181d74 100644 --- a/tacker/db/migration/alembic_migrations/versions/2774a42c7163_remove_service_related.py +++ b/tacker/db/migration/alembic_migrations/versions/2774a42c7163_remove_service_related.py @@ -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 # diff --git a/tacker/db/migration/alembic_migrations/versions/5246a6bd410f_multisite_vim.py b/tacker/db/migration/alembic_migrations/versions/5246a6bd410f_multisite_vim.py index e826e6e96..6d06de6dd 100644 --- a/tacker/db/migration/alembic_migrations/versions/5246a6bd410f_multisite_vim.py +++ b/tacker/db/migration/alembic_migrations/versions/5246a6bd410f_multisite_vim.py @@ -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') diff --git a/tacker/db/migration/alembic_migrations/versions/8f7145914cb0_remove_infra_driver_column.py b/tacker/db/migration/alembic_migrations/versions/8f7145914cb0_remove_infra_driver_column.py index 4d2c1eacd..7dd252f3e 100644 --- a/tacker/db/migration/alembic_migrations/versions/8f7145914cb0_remove_infra_driver_column.py +++ b/tacker/db/migration/alembic_migrations/versions/8f7145914cb0_remove_infra_driver_column.py @@ -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)) diff --git a/tacker/db/migration/alembic_migrations/versions/acf941e54075_add_error_reason_to_device.py b/tacker/db/migration/alembic_migrations/versions/acf941e54075_add_error_reason_to_device.py index 964b11d09..55efd0bcd 100644 --- a/tacker/db/migration/alembic_migrations/versions/acf941e54075_add_error_reason_to_device.py +++ b/tacker/db/migration/alembic_migrations/versions/acf941e54075_add_error_reason_to_device.py @@ -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') diff --git a/tacker/db/migration/alembic_migrations/versions/e8918cda6433_add_attributes_to_vnffg.py b/tacker/db/migration/alembic_migrations/versions/e8918cda6433_add_attributes_to_vnffg.py index 97d2c4228..173fe91fa 100644 --- a/tacker/db/migration/alembic_migrations/versions/e8918cda6433_add_attributes_to_vnffg.py +++ b/tacker/db/migration/alembic_migrations/versions/e8918cda6433_add_attributes_to_vnffg.py @@ -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') diff --git a/tacker/db/migration/cli.py b/tacker/db/migration/cli.py index 7462b8f13..f7094f729 100644 --- a/tacker/db/migration/cli.py +++ b/tacker/db/migration/cli.py @@ -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') diff --git a/tacker/tests/unit/test_db_migration.py b/tacker/tests/unit/test_db_migration.py index 42dd3ad80..748110c1d 100644 --- a/tacker/tests/unit/test_db_migration.py +++ b/tacker/tests/unit/test_db_migration.py @@ -98,21 +98,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