1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011 OpenStack LLC.
4
# Copyright 2012 Michael Still and Canonical Inc
7
# Licensed under the Apache License, Version 2.0 (the "License"); you may
8
# not use this file except in compliance with the License. You may obtain
9
# a copy of the License at
11
# http://www.apache.org/licenses/LICENSE-2.0
13
# Unless required by applicable law or agreed to in writing, software
14
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
# License for the specific language governing permissions and limitations
19
from sqlalchemy import MetaData, Table
20
from migrate import ForeignKeyConstraint
22
from nova.openstack.common import log as logging
25
LOG = logging.getLogger(__name__)
28
def upgrade(migrate_engine):
30
meta.bind = migrate_engine
31
instances = Table('instances', meta, autoload=True)
33
for table in ['block_device_mapping',
35
'instance_info_caches',
37
'security_group_instance_association']:
38
t = Table(table, meta, autoload=True)
42
columns=[t.c.instance_uuid],
43
refcolumns=[instances.c.uuid]).create()
45
LOG.error(_("foreign key constraint couldn't be created"))
49
def downgrade(migrate_engine):
51
meta.bind = migrate_engine
52
instances = Table('instances', meta, autoload=True)
54
for table in ['block_device_mapping',
56
'instance_info_caches',
58
'security_group_instance_association']:
59
t = Table(table, meta, autoload=True)
63
columns=[t.c.instance_uuid],
64
refcolumns=[instances.c.uuid]).drop()
66
LOG.error(_("foreign key constraint couldn't be dropped"))