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
"""Remove extra indexes
21
Revision ID: b6ae66d05e3
23
Create Date: 2013-08-19 15:54:43.529222
27
# revision identifiers, used by Alembic.
28
revision = 'b6ae66d05e3'
29
down_revision = '17738166b91'
31
from alembic import op
32
import sqlalchemy as sa
36
# ([dialects], table_name, index_name, create/delete, uniq/not_uniq,
38
(['mysql', 'sqlite', 'postgresql'],
40
'resource_user_id_project_id_key',
41
('user_id', 'project_id'), True, False, True),
42
(['mysql'], 'source', 'id', ('id',), False, True, False))
45
def index_cleanup(engine_names, table_name, uniq_name, columns, create,
49
if engine.name not in engine_names:
52
if limited and engine.name == 'mysql':
53
# For some versions of mysql we can get an error
54
# "Specified key was too long; max key length is 1000 bytes".
55
# We should create an index by hand in this case with limited
59
table = sa.Table(table_name, meta, autoload=True)
60
columns_mysql = ",".join((c + "(100)" for c in columns))
61
sql = ("create index %s ON %s (%s)" % (uniq_name, table,
65
op.create_index(uniq_name, table_name, columns, unique=unique)
68
op.drop_constraint(uniq_name, table_name, type='unique')
70
op.drop_index(uniq_name, table_name=table_name)
74
for (engine_names, table_name, uniq_name, columns, create, uniq,
76
index_cleanup(engine_names,
86
for (engine_names, table_name, uniq_name, columns, create, uniq,
88
index_cleanup(engine_names,