1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 OpenStack LLC.
4
# Copyright 2012 SolidFire 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, Integer, String, Table
21
from sqlalchemy import select, Column
23
from nova.openstack.common import log as logging
26
LOG = logging.getLogger(__name__)
29
def upgrade(migrate_engine):
31
meta.bind = migrate_engine
33
instances = Table('instances', meta, autoload=True)
34
volumes = Table('volumes', meta, autoload=True)
35
instance_uuid_column = Column('instance_uuid', String(36))
37
instance_uuid_column.create(volumes)
39
volumes.update().values(
42
instances.c.id == volumes.c.instance_id)
45
instance_uuid_column.drop()
47
fkeys = list(volumes.c.instance_id.foreign_keys)
50
fk_name = fkeys[0].constraint.name
52
columns=[volumes.c.instance_id],
53
refcolumns=[instances.c.id],
57
LOG.error(_("foreign key could not be dropped"))
60
volumes.c.instance_id.drop()
63
def downgrade(migrate_engine):
65
meta.bind = migrate_engine
67
instances = Table('instances', meta, autoload=True)
68
volumes = Table('volumes', meta, autoload=True)
69
instance_id_column = Column('instance_id', Integer)
71
instance_id_column.create(volumes)
73
volumes.update().values(
76
instances.c.uuid == volumes.c.instance_uuid)
79
instance_id_column.drop()
81
fkeys = list(volumes.c.instance_id.foreign_keys)
84
fk_name = fkeys[0].constraint.name
86
columns=[volumes.c.instance_id],
87
refcolumns=[instances.c.id],
88
name=fk_name).create()
91
LOG.error(_("foreign key could not be created"))
94
volumes.c.instance_uuid.drop()