1
# -*- encoding: utf-8 -*-
3
# Copyright 2010-2011 OpenStack Foundation
4
# Copyright 2012-2013 IBM Corp. #
6
# Authors: Svetlana Shturm <sshturm@mirantis.com>
8
# Licensed under the Apache License, Version 2.0 (the "License"); you may
9
# not use this file except in compliance with the License. You may obtain
10
# a copy of the License at
12
# http://www.apache.org/licenses/LICENSE-2.0
14
# Unless required by applicable law or agreed to in writing, software
15
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
# License for the specific language governing permissions and limitations
19
"""Fix name of UniqueConstraint according to OpenStack naming convention
21
Revision ID: 2c3ccda5a3ad
23
Create Date: 2013-08-19 18:06:03.409584
27
# revision identifiers, used by Alembic.
28
revision = '2c3ccda5a3ad'
29
down_revision = 'b6ae66d05e3'
31
from alembic import op
34
TABLE_NAME = 'sourceassoc'
35
UNIQ_NAME = 'uniq_sourceassoc0meter_id0user_id'
36
COLUMNS = ('meter_id', 'user_id')
39
def change_uniq(table_name, uniq_name, columns, downgrade=False):
42
if engine.name == 'sqlite':
44
if engine.name == 'mysql':
45
# For mysql dialect all dependent FK should be removed
46
# before renaming of constraint.
47
op.drop_constraint('fk_sourceassoc_meter_id',
50
op.drop_constraint('fk_sourceassoc_user_id',
54
op.drop_constraint(uniq_name, table_name=table_name, type='unique')
56
op.create_unique_constraint(uniq_name, table_name, columns)
57
if engine.name == 'mysql':
58
op.create_foreign_key('fk_sourceassoc_meter_id', table_name, 'meter',
60
op.create_foreign_key('fk_sourceassoc_user_id', table_name, 'user',
65
change_uniq(TABLE_NAME, UNIQ_NAME, COLUMNS)
69
change_uniq(TABLE_NAME, UNIQ_NAME, COLUMNS, downgrade=True)