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 migrate import ForeignKeyConstraint
20
from sqlalchemy import MetaData, String, Table
21
from sqlalchemy import select, Column, ForeignKey, Integer
23
from nova.openstack.common import log as logging
26
LOG = logging.getLogger(__name__)
29
def upgrade(migrate_engine):
31
meta.bind = migrate_engine
32
sgia = Table('security_group_instance_association', meta, autoload=True)
33
instances = Table('instances', meta, autoload=True)
34
uuid_column = Column('instance_uuid', String(36))
35
uuid_column.create(sgia)
41
instances.c.id == sgia.c.instance_id)
47
fkeys = list(sgia.c.instance_id.foreign_keys)
50
fkey_name = fkeys[0].constraint.name
52
columns=[sgia.c.instance_id],
53
refcolumns=[instances.c.id],
54
name=fkey_name).drop()
56
LOG.error(_("foreign key constraint couldn't be removed"))
59
sgia.c.instance_id.drop()
62
def downgrade(migrate_engine):
64
meta.bind = migrate_engine
65
sgia = Table('security_group_instance_association', meta, autoload=True)
66
instances = Table('instances', meta, autoload=True)
67
id_column = Column('instance_id', Integer, ForeignKey('instances.id'))
68
id_column.create(sgia)
74
instances.c.uuid == sgia.c.instance_uuid)
80
sgia.c.instance_uuid.drop()