Coverage for manila/db/migrations/alembic/versions/3db9992c30f3_transform_statuses_to_lowercase.py: 100%
16 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 2015 Mirantis Inc.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
16"""Transform statuses to lowercase
18Revision ID: 3db9992c30f3
19Revises: 533646c7af38
20Create Date: 2015-05-28 19:30:35.645773
22"""
24# revision identifiers, used by Alembic.
25revision = '3db9992c30f3'
26down_revision = '533646c7af38'
28from alembic import op
29import sqlalchemy as sa
31from manila.db.migrations import utils
34def upgrade():
35 # NOTE(vponomaryov): shares has some statuses as uppercase, so
36 # transform them in addition to statuses of share servers.
37 for table in ('shares', 'share_servers'):
38 _transform_case(table, make_upper=False)
41def downgrade():
42 # NOTE(vponomaryov): transform share server statuses to uppercase and
43 # leave share statuses as is.
44 _transform_case('share_servers', make_upper=True)
47def _transform_case(table_name, make_upper):
48 connection = op.get_bind()
49 table = utils.load_table(table_name, connection)
50 case = sa.func.upper if make_upper else sa.func.lower
52 for row in connection.execute(table.select()):
53 op.execute(
54 table.update().where( # pylint: disable=no-value-for-parameter
55 table.c.id == row.id
56 ).values({'status': case(row.status)})
57 )