1
# Copyright 2011 OpenStack LLC.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
16
from sqlalchemy import MetaData, Table
17
from migrate import ForeignKeyConstraint
19
from nova import log as logging
21
LOG = logging.getLogger(__name__)
24
def upgrade(migrate_engine):
26
meta.bind = migrate_engine
27
dialect = migrate_engine.url.get_dialect().name
30
fixed_ips = Table('fixed_ips', meta, autoload=True)
31
virtual_interfaces = Table('virtual_interfaces', meta, autoload=True)
33
# add foreignkey if not sqlite
35
if not dialect.startswith('sqlite'):
36
ForeignKeyConstraint(columns=[fixed_ips.c.virtual_interface_id],
37
refcolumns=[virtual_interfaces.c.id]).create()
39
LOG.error(_("foreign key constraint couldn't be added"))
43
def downgrade(migrate_engine):
45
meta.bind = migrate_engine
46
dialect = migrate_engine.url.get_dialect().name
49
fixed_ips = Table('fixed_ips', meta, autoload=True)
50
virtual_interfaces = Table('virtual_interfaces', meta, autoload=True)
52
# drop foreignkey if not sqlite
54
if not dialect.startswith('sqlite'):
55
ForeignKeyConstraint(columns=[fixed_ips.c.virtual_interface_id],
56
refcolumns=[virtual_interfaces.c.id]).drop()
58
LOG.error(_("foreign key constraint couldn't be dropped"))