diff --git a/solum/objects/sqlalchemy/component.py b/solum/objects/sqlalchemy/component.py index 807d85d13..08ba0185b 100644 --- a/solum/objects/sqlalchemy/component.py +++ b/solum/objects/sqlalchemy/component.py @@ -34,8 +34,8 @@ class Component(sql.Base, abstract.Component): name = sa.Column(sa.String(100)) description = sa.Column(sa.String(255)) tags = sa.Column(sa.Text) - assembly_id = sa.Column(sa.Integer) - parent_component_id = sa.Column(sa.Integer) + assembly_id = sa.Column(sa.Integer, sa.ForeignKey('assembly.id')) + parent_component_id = sa.Column(sa.Integer, sa.ForeignKey('component.id')) resource_uri = sa.Column(sa.String(1024)) @property diff --git a/solum/objects/sqlalchemy/migration/alembic_migrations/versions/18b94e085cf9_update_component_foreign_keys.py b/solum/objects/sqlalchemy/migration/alembic_migrations/versions/18b94e085cf9_update_component_foreign_keys.py new file mode 100644 index 000000000..a5b26a634 --- /dev/null +++ b/solum/objects/sqlalchemy/migration/alembic_migrations/versions/18b94e085cf9_update_component_foreign_keys.py @@ -0,0 +1,38 @@ +# +# 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. + +"""update component foreign keys + +Revision ID: 18b94e085cf9 +Revises: 12d90235e174 +Create Date: 2014-03-10 18:04:58.733470 + +""" +from alembic import op + +# revision identifiers, used by Alembic. +revision = '18b94e085cf9' +down_revision = '12d90235e174' + + +def upgrade(): + op.create_foreign_key('fk_component_assembly', 'component', + 'assembly', ['assembly_id'], ['id']) + op.create_foreign_key('fk_parent_component', 'component', + 'component', ['parent_component_id'], ['id']) + + +def downgrade(): + op.drop_constraint('fk_component_assembly', 'component', + type_='foreignkey') + op.drop_constraint('fk_parent_component', 'component', type_='foreignkey') diff --git a/solum/tests/objects/test_component.py b/solum/tests/objects/test_component.py index 69f9dfa61..ca2df5fcc 100644 --- a/solum/tests/objects/test_component.py +++ b/solum/tests/objects/test_component.py @@ -29,6 +29,8 @@ class TestComponent(base.BaseTestCase): 'uuid': 'ce43e347f0b0422825245b3e5f140a81cef6e65b', 'name': 'component1', 'description': 'test component', + 'assembly_id': '42d42d', + 'parent_component_id': '87d98s', 'tags': 'component tags'}] utils.create_models_from_data(component.Component, self.data, self.ctx)