-
Notifications
You must be signed in to change notification settings - Fork 527
/
ocata_contract01_drop_is_public.py
74 lines (56 loc) · 2.17 KB
/
ocata_contract01_drop_is_public.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""remove is_public from images
Revision ID: ocata_contract01
Revises: mitaka02
Create Date: 2017-01-27 12:58:16.647499
"""
from alembic import op
from sqlalchemy import Enum
from glance.cmd import manage
from glance.db import migration
# revision identifiers, used by Alembic.
revision = 'ocata_contract01'
down_revision = 'mitaka02'
branch_labels = ('ocata01', migration.CONTRACT_BRANCH)
depends_on = 'ocata_expand01'
MYSQL_DROP_INSERT_TRIGGER = """
DROP TRIGGER insert_visibility;
"""
MYSQL_DROP_UPDATE_TRIGGER = """
DROP TRIGGER update_visibility;
"""
def _drop_column():
with op.batch_alter_table('images') as batch_op:
batch_op.drop_index('ix_images_is_public')
batch_op.drop_column('is_public')
def _drop_triggers(connection):
engine_name = connection.engine.name
if engine_name == "mysql":
op.execute(MYSQL_DROP_INSERT_TRIGGER)
op.execute(MYSQL_DROP_UPDATE_TRIGGER)
def _set_nullability_and_default_on_visibility():
# NOTE(hemanthm): setting the default on 'visibility' column
# to 'shared'. Also, marking it as non-nullable.
existing_type = Enum('private', 'public', 'shared', 'community',
name='image_visibility')
with op.batch_alter_table('images') as batch_op:
batch_op.alter_column('visibility',
nullable=False,
server_default='shared',
existing_type=existing_type)
def upgrade():
bind = op.get_bind()
_drop_column()
if manage.USE_TRIGGERS:
_drop_triggers(bind)
_set_nullability_and_default_on_visibility()