Coverage for manila/db/migrations/alembic/versions/533646c7af38_remove_unused_attr_status.py: 78%

23 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright 2015 Mirantis, Inc. 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); you may 

4# not use this file except in compliance with the License. You may obtain 

5# a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

12# License for the specific language governing permissions and limitations 

13# under the License. 

14 

15"""Remove unused attr status 

16 

17Revision ID: 533646c7af38 

18Revises: 3a482171410f 

19Create Date: 2015-05-28 13:13:47.651353 

20 

21""" 

22 

23# revision identifiers, used by Alembic. 

24revision = '533646c7af38' 

25down_revision = '3a482171410f' 

26 

27from alembic import op 

28from oslo_log import log 

29import sqlalchemy as sql 

30 

31from manila.common import constants 

32 

33LOG = log.getLogger(__name__) 

34COLUMN_NAME = 'status' 

35TABLE_NAMES = ('network_allocations', 'security_services') 

36 

37 

38def upgrade(): 

39 for t_name in TABLE_NAMES: 

40 try: 

41 op.drop_column(t_name, COLUMN_NAME) 

42 except Exception: 

43 LOG.error("Column '%s' could not be dropped", COLUMN_NAME) 

44 raise 

45 

46 

47def downgrade(): 

48 for t_name in TABLE_NAMES: 

49 try: 

50 op.add_column( 

51 t_name, 

52 sql.Column( 

53 COLUMN_NAME, 

54 # NOTE(vponomaryov): original type of attr was enum. But 

55 # alembic is buggy with enums [1], so use string type 

56 # instead. Anyway we have no reason to keep enum/constraint 

57 # on specific set of possible statuses because they have 

58 # not been used. 

59 # [1] - https://bitbucket.org/zzzeek/alembic/ 

60 # issue/89/opadd_column-and-opdrop_column-should 

61 sql.String(255), 

62 default=constants.STATUS_NEW, 

63 ), 

64 ) 

65 except Exception: 

66 LOG.error("Column '%s' could not be added", COLUMN_NAME) 

67 raise