Coverage for manila/db/migrations/alembic/versions/3651e16d7c43_add_consistency_groups.py: 73%
52 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright (c) 2015 Alex Meade
2# Licensed under the Apache License, Version 2.0 (the "License"); you may
3# not use this file except in compliance with the License. You may obtain
4# a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11# License for the specific language governing permissions and limitations
12# under the License.
14"""Create Consistency Groups Tables and Columns
16Revision ID: 3651e16d7c43
17Revises: 55761e5f59c5
18Create Date: 2015-07-29 13:17:15.940454
20"""
22# revision identifiers, used by Alembic.
23revision = '3651e16d7c43'
24down_revision = '55761e5f59c5'
26SHARE_NETWORK_FK_CONSTRAINT_NAME = "fk_cg_share_network_id"
27SHARE_SERVER_FK_CONSTRAINT_NAME = "fk_cg_share_server_id"
28SHARES_CG_FK_CONSTRAINT_NAME = "fk_shares_consistency_group_id"
29CG_MAP_FK_CONSTRAINT_NAME = "fk_cgstm_cg_id"
30SHARE_TYPE_FK_CONSTRAINT_NAME = "fk_cgstm_share_type_id"
31CGSNAP_CG_ID_FK_CONSTRAINT_NAME = "fk_cgsnapshots_consistency_group_id"
32CGSNAP_MEM_SHARETYPE_FK_CONSTRAINT_NAME = "fk_cgsnapshot_members_share_type_id"
33CGSNAP_MEM_SNAP_ID_FK_CONSTRAINT_NAME = "fk_cgsnapshot_members_cgsnapshot_id"
34CGSNAP_MEM_SHARE_FK_CONSTRAINT_NAME = "fk_cgsnapshot_members_share_id"
35CGSNAP_MEM_INST_FK_CONSTRAINT_NAME = "fk_cgsnapshot_members_share_instance_id"
37from alembic import op
38from oslo_log import log
39import sqlalchemy as sa
41LOG = log.getLogger(__name__)
44def upgrade():
45 # New table - consistency_groups
46 op.create_table(
47 'consistency_groups',
48 sa.Column('id', sa.String(36), primary_key=True, nullable=False),
49 sa.Column('created_at', sa.DateTime),
50 sa.Column('updated_at', sa.DateTime),
51 sa.Column('deleted_at', sa.DateTime),
52 sa.Column('deleted', sa.String(36), default='False'),
54 sa.Column('user_id', sa.String(length=255), nullable=False),
55 sa.Column('project_id', sa.String(length=255), nullable=False),
56 sa.Column('host', sa.String(length=255)),
57 sa.Column('name', sa.String(length=255)),
58 sa.Column('description', sa.String(length=255)),
59 sa.Column('status', sa.String(length=255)),
60 sa.Column('source_cgsnapshot_id', sa.String(length=36)),
61 sa.Column('share_network_id', sa.String(length=36),
62 sa.ForeignKey('share_networks.id',
63 name=SHARE_NETWORK_FK_CONSTRAINT_NAME),
64 nullable=True),
65 sa.Column('share_server_id', sa.String(length=36),
66 sa.ForeignKey('share_servers.id',
67 name=SHARE_SERVER_FK_CONSTRAINT_NAME),
68 nullable=True),
70 mysql_engine='InnoDB',
71 mysql_charset='utf8')
73 op.add_column(
74 'shares',
75 sa.Column('consistency_group_id',
76 sa.String(36),
77 sa.ForeignKey('consistency_groups.id',
78 name=SHARES_CG_FK_CONSTRAINT_NAME)))
80 op.add_column('shares',
81 sa.Column('source_cgsnapshot_member_id', sa.String(36)))
83 op.create_table(
84 'consistency_group_share_type_mappings',
85 sa.Column('id', sa.String(36), primary_key=True, nullable=False),
86 sa.Column('created_at', sa.DateTime),
87 sa.Column('updated_at', sa.DateTime),
88 sa.Column('deleted_at', sa.DateTime),
89 sa.Column('deleted', sa.String(36), default='False'),
91 sa.Column('consistency_group_id', sa.String(length=36),
92 sa.ForeignKey('consistency_groups.id',
93 name=CG_MAP_FK_CONSTRAINT_NAME),
94 nullable=False),
95 sa.Column('share_type_id', sa.String(length=36),
96 sa.ForeignKey('share_types.id',
97 name=SHARE_TYPE_FK_CONSTRAINT_NAME),
98 nullable=False),
99 mysql_engine='InnoDB',
100 mysql_charset='utf8')
102 op.create_table(
103 'cgsnapshots',
104 sa.Column('id', sa.String(36), primary_key=True, nullable=False),
105 sa.Column('created_at', sa.DateTime),
106 sa.Column('updated_at', sa.DateTime),
107 sa.Column('deleted_at', sa.DateTime),
108 sa.Column('deleted', sa.String(36), default='False'),
109 sa.Column('user_id', sa.String(length=255), nullable=False),
110 sa.Column('project_id', sa.String(length=255), nullable=False),
112 sa.Column('consistency_group_id', sa.String(length=36),
113 sa.ForeignKey('consistency_groups.id',
114 name=CGSNAP_CG_ID_FK_CONSTRAINT_NAME),
115 nullable=False),
117 sa.Column('name', sa.String(length=255)),
118 sa.Column('description', sa.String(length=255)),
119 sa.Column('status', sa.String(length=255)),
120 mysql_engine='InnoDB',
121 mysql_charset='utf8')
123 op.create_table(
124 'cgsnapshot_members',
125 sa.Column('id', sa.String(36), primary_key=True, nullable=False),
126 sa.Column('created_at', sa.DateTime),
127 sa.Column('updated_at', sa.DateTime),
128 sa.Column('deleted_at', sa.DateTime),
129 sa.Column('deleted', sa.String(36), default='False'),
130 sa.Column('user_id', sa.String(length=255), nullable=False),
131 sa.Column('project_id', sa.String(length=255), nullable=False),
133 sa.Column('cgsnapshot_id', sa.String(length=36),
134 sa.ForeignKey('cgsnapshots.id',
135 name=CGSNAP_MEM_SNAP_ID_FK_CONSTRAINT_NAME),
136 nullable=False),
137 sa.Column('share_instance_id', sa.String(length=36),
138 sa.ForeignKey('share_instances.id',
139 name=CGSNAP_MEM_INST_FK_CONSTRAINT_NAME),
140 nullable=False),
141 sa.Column('share_id', sa.String(length=36),
142 sa.ForeignKey('shares.id',
143 name=CGSNAP_MEM_SHARE_FK_CONSTRAINT_NAME),
144 nullable=False),
145 sa.Column('share_type_id', sa.String(length=36),
146 sa.ForeignKey('share_types.id',
147 name=CGSNAP_MEM_SHARETYPE_FK_CONSTRAINT_NAME),
148 nullable=False),
150 sa.Column('size', sa.Integer),
151 sa.Column('status', sa.String(length=255)),
152 sa.Column('share_proto', sa.String(length=255)),
153 mysql_engine='InnoDB',
154 mysql_charset='utf8')
157def downgrade():
158 try:
159 op.drop_table('cgsnapshot_members')
160 except Exception:
161 LOG.exception("Error Dropping 'cgsnapshot_members' table.")
163 try:
164 op.drop_table('cgsnapshots')
165 except Exception:
166 LOG.exception("Error Dropping 'cgsnapshots' table.")
168 try:
169 op.drop_table('consistency_group_share_type_mappings')
170 except Exception:
171 LOG.exception("Error Dropping "
172 "'consistency_group_share_type_mappings' table.")
174 try:
175 op.drop_column('shares', 'source_cgsnapshot_member_id')
176 except Exception:
177 LOG.exception("Error Dropping 'source_cgsnapshot_member_id' "
178 "column from 'shares' table.")
180 try:
181 op.drop_constraint(SHARES_CG_FK_CONSTRAINT_NAME,
182 'shares',
183 type_='foreignkey')
184 except Exception:
185 LOG.exception("Error Dropping '%s' constraint.",
186 SHARES_CG_FK_CONSTRAINT_NAME)
188 try:
189 op.drop_column('shares', 'consistency_group_id')
190 except Exception:
191 LOG.exception("Error Dropping 'consistency_group_id' column "
192 "from 'shares' table.")
194 try:
195 op.drop_table('consistency_groups')
196 except Exception:
197 LOG.exception("Error Dropping 'consistency_groups' table.")