diff --git a/heat/db/sqlalchemy/migrate_repo/versions/064_raw_template_predecessor.py b/heat/db/sqlalchemy/migrate_repo/versions/064_raw_template_predecessor.py new file mode 100644 index 0000000000..984a152520 --- /dev/null +++ b/heat/db/sqlalchemy/migrate_repo/versions/064_raw_template_predecessor.py @@ -0,0 +1,52 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import migrate +import sqlalchemy + +from heat.db.sqlalchemy import utils as migrate_utils + + +def upgrade(migrate_engine): + if migrate_engine.name == 'sqlite': + upgrade_sqlite(migrate_engine) + return + + meta = sqlalchemy.MetaData() + meta.bind = migrate_engine + + tmpl_table = sqlalchemy.Table('raw_template', meta, autoload=True) + + # drop constraint + fkey = migrate.ForeignKeyConstraint( + columns=[tmpl_table.c.predecessor], + refcolumns=[tmpl_table.c.id], + name='predecessor_fkey_ref') + fkey.drop() + tmpl_table.c.predecessor.drop() + + +def upgrade_sqlite(migrate_engine): + meta = sqlalchemy.MetaData() + meta.bind = migrate_engine + + tmpl_table = sqlalchemy.Table('raw_template', meta, autoload=True) + ignorecols = [tmpl_table.c.predecessor.name] + new_template = migrate_utils.clone_table('new_raw_template', + tmpl_table, + meta, ignorecols=ignorecols) + # migrate stacks to new table + migrate_utils.migrate_data(migrate_engine, + tmpl_table, + new_template, + skip_columns=['predecessor']) diff --git a/heat/db/sqlalchemy/models.py b/heat/db/sqlalchemy/models.py index 75f66245f3..287bf4b2b2 100644 --- a/heat/db/sqlalchemy/models.py +++ b/heat/db/sqlalchemy/models.py @@ -99,8 +99,6 @@ class RawTemplate(BASE, HeatBase): template = sqlalchemy.Column(types.Json) files = sqlalchemy.Column(types.Json) environment = sqlalchemy.Column('environment', types.Json) - predecessor = sqlalchemy.Column('predecessor', sqlalchemy.Integer, - sqlalchemy.ForeignKey('raw_template.id')) class StackTag(BASE, HeatBase): diff --git a/heat/objects/raw_template.py b/heat/objects/raw_template.py index 76e5528b26..d67df97eb0 100644 --- a/heat/objects/raw_template.py +++ b/heat/objects/raw_template.py @@ -40,7 +40,6 @@ class RawTemplate( 'files': heat_fields.JsonField(nullable=True), 'template': heat_fields.JsonField(), 'environment': heat_fields.JsonField(), - 'predecessor': fields.IntegerField(), } @staticmethod diff --git a/heat/tests/db/test_migrations.py b/heat/tests/db/test_migrations.py index 613b2e34bd..ac20e13fa6 100644 --- a/heat/tests/db/test_migrations.py +++ b/heat/tests/db/test_migrations.py @@ -613,6 +613,10 @@ class HeatMigrationsCheckers(test_migrations.WalkVersionsMixin, self.assertColumnExists(engine, 'resource', 'properties_data_encrypted') + def _check_064(self, engine, data): + self.assertColumnNotExists(engine, 'raw_template', + 'predecessor') + class TestHeatMigrationsMySQL(HeatMigrationsCheckers, test_base.MySQLOpportunisticTestCase):