Coverage for manila/db/migrations/alembic/versions/478c445d8d3e_add_security_service_update_control_fields.py: 74%
31 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# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
13"""add_security_service_update_control_fields
15Revision ID: 478c445d8d3e
16Revises: 0c23aec99b74
17Create Date: 2020-12-07 12:33:41.444202
19"""
21# revision identifiers, used by Alembic.
22revision = '478c445d8d3e'
23down_revision = '0c23aec99b74'
25from alembic import op
26from manila.common import constants
27from oslo_log import log
28import sqlalchemy as sa
30SHARE_SERVERS_TABLE = 'share_servers'
31SHARE_NETWORKS_TABLE = 'share_networks'
32ASYNC_OPERATION_DATA_TABLE = 'async_operation_data'
33LOG = log.getLogger(__name__)
36def upgrade():
37 context = op.get_context()
38 mysql_dl = context.bind.dialect.name == 'mysql'
39 datetime_type = (sa.dialects.mysql.DATETIME(fsp=6)
40 if mysql_dl else sa.DateTime)
41 try:
42 op.create_table(
43 ASYNC_OPERATION_DATA_TABLE,
44 sa.Column('created_at', datetime_type),
45 sa.Column('updated_at', datetime_type),
46 sa.Column('deleted_at', datetime_type),
47 sa.Column('deleted', sa.Integer, default=0),
48 sa.Column('entity_uuid', sa.String(36),
49 nullable=False, primary_key=True),
50 sa.Column('key', sa.String(255),
51 nullable=False, primary_key=True),
52 sa.Column('value', sa.String(1023), nullable=False),
53 mysql_engine='InnoDB',
54 mysql_charset='utf8',
55 )
56 op.add_column(
57 SHARE_SERVERS_TABLE,
58 sa.Column('security_service_update_support', sa.Boolean,
59 nullable=False, server_default=sa.sql.false())
60 )
61 op.add_column(
62 SHARE_NETWORKS_TABLE,
63 sa.Column('status', sa.String(36), nullable=False,
64 server_default=constants.STATUS_NETWORK_ACTIVE))
65 except Exception:
66 msg_args = {
67 'async_op_table': ASYNC_OPERATION_DATA_TABLE,
68 'sec_serv_column': 'share_servers.security_service_update_support',
69 'shr_net_column': 'share_networks.status',
70 }
71 LOG.error('Table %(async_op_table)s and table columns '
72 '%(sec_serv_column)s and %(shr_net_column)s were not'
73 ' created!', msg_args)
74 raise
77def downgrade():
78 try:
79 op.drop_table(ASYNC_OPERATION_DATA_TABLE)
80 op.drop_column(SHARE_SERVERS_TABLE, 'security_service_update_support')
81 op.drop_column(SHARE_NETWORKS_TABLE, 'status')
82 except Exception:
83 msg_args = {
84 'async_op_table': ASYNC_OPERATION_DATA_TABLE,
85 'sec_serv_column': 'share_servers.security_service_update_support',
86 'shr_net_column': 'share_networks.status',
87 }
88 LOG.error('Table %(async_op_table)s and table columns '
89 '%(sec_serv_column)s and %(shr_net_column)s were not '
90 'dropped!', msg_args)
91 raise