Coverage for manila/db/migrations/alembic/versions/9afbe2df4945_add_backup.py: 59%

29 statements  

« 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. 

12 

13"""add backup 

14 

15Revision ID: 9afbe2df4945 

16Revises: aebe2a413e13 

17Create Date: 2022-04-21 23:06:59.144695 

18 

19""" 

20 

21# revision identifiers, used by Alembic. 

22revision = '9afbe2df4945' 

23down_revision = 'aebe2a413e13' 

24 

25from alembic import op 

26from oslo_log import log 

27import sqlalchemy as sa 

28 

29 

30LOG = log.getLogger(__name__) 

31 

32share_backups_table_name = 'share_backups' 

33 

34 

35def upgrade(): 

36 """Add backup attributes.""" 

37 

38 try: 

39 op.create_table( 

40 share_backups_table_name, 

41 sa.Column('id', sa.String(length=36), 

42 primary_key=True, nullable=False), 

43 sa.Column('created_at', sa.DateTime), 

44 sa.Column('updated_at', sa.DateTime), 

45 sa.Column('deleted_at', sa.DateTime), 

46 sa.Column('deleted', sa.String(length=36), default='False'), 

47 sa.Column('user_id', sa.String(255)), 

48 sa.Column('project_id', sa.String(255)), 

49 sa.Column('availability_zone', sa.String(255)), 

50 sa.Column('fail_reason', sa.String(255)), 

51 sa.Column('display_name', sa.String(255)), 

52 sa.Column('display_description', sa.String(255)), 

53 sa.Column('host', sa.String(255)), 

54 sa.Column('topic', sa.String(255)), 

55 sa.Column('status', sa.String(255)), 

56 sa.Column('progress', sa.String(32)), 

57 sa.Column('restore_progress', sa.String(32)), 

58 sa.Column('size', sa.Integer), 

59 sa.Column('share_id', sa.String(36), 

60 sa.ForeignKey('shares.id', 

61 name="fk_backups_share_id_shares")), 

62 mysql_engine='InnoDB', 

63 mysql_charset='utf8' 

64 ) 

65 except Exception: 

66 LOG.error("Table |%s| not created!", 

67 share_backups_table_name) 

68 raise 

69 

70 try: 

71 op.add_column( 

72 'shares', 

73 sa.Column('source_backup_id', sa.String(36), nullable=True)) 

74 except Exception: 

75 LOG.error("Column can not be added for 'shares' table!") 

76 raise 

77 

78 

79def downgrade(): 

80 """Remove share backup attributes and table share_backups.""" 

81 try: 

82 op.drop_table(share_backups_table_name) 

83 except Exception: 

84 LOG.error("%s table not dropped.", share_backups_table_name) 

85 raise 

86 

87 try: 

88 op.drop_column('shares', 'source_backup_id') 

89 except Exception: 

90 LOG.error("Column can not be dropped for 'shares' table!") 

91 raise