Drop the container_actions table foreign key
container_actions.container_uuid is a foreign key of container.uuid. When user delete a container, zun will delete the data of the container from database. With this foreign key contrain, it will generate error in deleting container data. This commit remove the container_actions table's foreign key. Using orm.relationship to join container_actions.container_uuid and container.uuid. Change-Id: Iac25adc69495826e6d5b0109eb729a0387e63c0b
This commit is contained in:
parent
220fb92cb6
commit
9840fb9ca0
@ -0,0 +1,43 @@
|
||||
# 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.
|
||||
|
||||
"""drop foreign key of container_actions container_uuid
|
||||
|
||||
Revision ID: 8b0082d9e7c1
|
||||
Revises: b6bfca998431
|
||||
Create Date: 2017-12-14 15:32:38.520594
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '8b0082d9e7c1'
|
||||
down_revision = 'b6bfca998431'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy.engine.reflection import Inspector as insp
|
||||
|
||||
CONTAINER_ACTIONS = 'container_actions'
|
||||
CONTAINER = 'container'
|
||||
|
||||
|
||||
def upgrade():
|
||||
bind = op.get_bind()
|
||||
|
||||
inspector = insp.from_engine(bind)
|
||||
foreign_keys = inspector.get_foreign_keys(CONTAINER_ACTIONS)
|
||||
|
||||
for foreign_key in foreign_keys:
|
||||
if foreign_key.get('referred_table') == CONTAINER:
|
||||
op.drop_constraint(foreign_key.get('name'), CONTAINER_ACTIONS,
|
||||
type_="foreignkey")
|
@ -427,6 +427,11 @@ class ContainerAction(Base):
|
||||
start_time = Column(DateTime, default=timeutils.utcnow)
|
||||
finish_time = Column(DateTime)
|
||||
message = Column(String(255))
|
||||
container = orm.relationship(
|
||||
"Container", backref="container_actions",
|
||||
foreign_keys=container_uuid,
|
||||
primaryjoin='and_(ContainerAction.container_uuid == Container.uuid)'
|
||||
)
|
||||
|
||||
|
||||
class ContainerActionEvent(Base):
|
||||
|
Loading…
Reference in New Issue
Block a user