~ubuntu-branches/ubuntu/vivid/ceilometer/vivid

« back to all changes in this revision

Viewing changes to ceilometer/storage/sqlalchemy/alembic/versions/2c3ccda5a3ad_fix_uniq_name.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-03-06 14:44:28 UTC
  • mto: (28.1.1 utopic-proposed) (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: package-import@ubuntu.com-20140306144428-rvphsh4igwyulzf0
Tags: upstream-2014.1~b3
ImportĀ upstreamĀ versionĀ 2014.1~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
 
#
3
 
# Copyright 2010-2011 OpenStack Foundation
4
 
# Copyright 2012-2013 IBM Corp. #
5
 
#
6
 
# Authors: Svetlana Shturm <sshturm@mirantis.com>
7
 
#
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
11
 
#
12
 
#      http://www.apache.org/licenses/LICENSE-2.0
13
 
#
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
18
 
# under the License.
19
 
"""Fix name of UniqueConstraint according to OpenStack naming convention
20
 
 
21
 
Revision ID: 2c3ccda5a3ad
22
 
Revises: b6ae66d05e3
23
 
Create Date: 2013-08-19 18:06:03.409584
24
 
 
25
 
"""
26
 
 
27
 
# revision identifiers, used by Alembic.
28
 
revision = '2c3ccda5a3ad'
29
 
down_revision = 'b6ae66d05e3'
30
 
 
31
 
from alembic import op
32
 
 
33
 
 
34
 
TABLE_NAME = 'sourceassoc'
35
 
UNIQ_NAME = 'uniq_sourceassoc0meter_id0user_id'
36
 
COLUMNS = ('meter_id', 'user_id')
37
 
 
38
 
 
39
 
def change_uniq(table_name, uniq_name, columns, downgrade=False):
40
 
    bind = op.get_bind()
41
 
    engine = bind.engine
42
 
    if engine.name == 'sqlite':
43
 
        return
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',
48
 
                           table_name,
49
 
                           type='foreignkey')
50
 
        op.drop_constraint('fk_sourceassoc_user_id',
51
 
                           table_name,
52
 
                           type='foreignkey')
53
 
    if downgrade:
54
 
        op.drop_constraint(uniq_name, table_name=table_name, type='unique')
55
 
    else:
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',
59
 
                              ['meter_id'], ['id'])
60
 
        op.create_foreign_key('fk_sourceassoc_user_id', table_name, 'user',
61
 
                              ['user_id'], ['id'])
62
 
 
63
 
 
64
 
def upgrade():
65
 
    change_uniq(TABLE_NAME, UNIQ_NAME, COLUMNS)
66
 
 
67
 
 
68
 
def downgrade():
69
 
    change_uniq(TABLE_NAME, UNIQ_NAME, COLUMNS, downgrade=True)