Coverage for manila/db/migrations/alembic/versions/a77e2ad5012d_add_share_snapshot_access.py: 100%

19 statements  

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

1# Copyright (c) 2016 Hitachi Data Systems. 

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. 

15 

16"""add_share_snapshot_access 

17 

18Revision ID: a77e2ad5012d 

19Revises: e1949a93157a 

20Create Date: 2016-07-15 13:32:19.417771 

21 

22""" 

23 

24# revision identifiers, used by Alembic. 

25revision = 'a77e2ad5012d' 

26down_revision = 'e1949a93157a' 

27 

28from manila.common import constants 

29from manila.db.migrations import utils 

30 

31from alembic import op 

32 

33import sqlalchemy as sa 

34 

35 

36def upgrade(): 

37 op.create_table( 

38 'share_snapshot_access_map', 

39 sa.Column('id', sa.String(36), primary_key=True), 

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

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

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

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

44 sa.Column('share_snapshot_id', sa.String(36), 

45 sa.ForeignKey('share_snapshots.id', 

46 name='ssam_snapshot_fk')), 

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

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

49 mysql_charset='utf8' 

50 ) 

51 

52 op.create_table( 

53 'share_snapshot_instance_access_map', 

54 sa.Column('id', sa.String(36), primary_key=True), 

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

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

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

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

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

60 sa.ForeignKey('share_snapshot_instances.id', 

61 name='ssiam_snapshot_instance_fk')), 

62 sa.Column('access_id', sa.String(36), 

63 sa.ForeignKey('share_snapshot_access_map.id', 

64 name='ssam_access_fk')), 

65 sa.Column('state', sa.String(255), 

66 default=constants.ACCESS_STATE_QUEUED_TO_APPLY), 

67 mysql_charset='utf8' 

68 ) 

69 

70 op.create_table( 

71 'share_snapshot_instance_export_locations', 

72 sa.Column('id', sa.String(36), primary_key=True), 

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

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

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

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

77 sa.Column('share_snapshot_instance_id', sa.String(36), 

78 sa.ForeignKey('share_snapshot_instances.id', 

79 name='ssiel_snapshot_instance_fk')), 

80 sa.Column('path', sa.String(2000)), 

81 sa.Column('is_admin_only', sa.Boolean, default=False, nullable=False), 

82 mysql_charset='utf8' 

83 ) 

84 

85 op.add_column('shares', 

86 sa.Column('mount_snapshot_support', sa.Boolean, 

87 default=False)) 

88 

89 connection = op.get_bind() 

90 shares_table = utils.load_table('shares', connection) 

91 

92 # pylint: disable=no-value-for-parameter 

93 op.execute( 

94 shares_table.update().where( 

95 shares_table.c.deleted == 'False').values({ 

96 'mount_snapshot_support': False, 

97 }) 

98 ) 

99 

100 

101def downgrade(): 

102 op.drop_table('share_snapshot_instance_export_locations') 

103 op.drop_table('share_snapshot_instance_access_map') 

104 op.drop_table('share_snapshot_access_map') 

105 op.drop_column('shares', 'mount_snapshot_support')