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

13 statements  

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

1# Copyright (c) 2016 Clinton Knight. All rights reserved. 

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"""add_revert_to_snapshot_support 

16 

17Revision ID: 87ce15c59bbe 

18Revises: 95e3cf760840 

19Create Date: 2016-08-18 00:12:34.587018 

20 

21""" 

22 

23# revision identifiers, used by Alembic. 

24revision = '87ce15c59bbe' 

25down_revision = '95e3cf760840' 

26 

27from alembic import op 

28import sqlalchemy as sa 

29 

30 

31def upgrade(): 

32 """Performs DB upgrade to add revert_to_snapshot_support. 

33 

34 Add attribute 'revert_to_snapshot_support' to Share model. 

35 """ 

36 with sa.orm.Session(bind=op.get_bind()) as session: 

37 

38 # Add create_share_from_snapshot_support attribute to shares table 

39 op.add_column( 

40 'shares', 

41 sa.Column('revert_to_snapshot_support', sa.Boolean, default=False)) 

42 

43 # Set revert_to_snapshot_support on each share 

44 shares_table = sa.Table( 

45 'shares', 

46 sa.MetaData(), 

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

48 sa.Column('deleted', sa.String(length=36)), 

49 sa.Column('revert_to_snapshot_support', sa.Boolean), 

50 ) 

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

52 update = shares_table.update().where( 

53 shares_table.c.deleted == 'False').values( 

54 revert_to_snapshot_support=False) 

55 session.execute(update) 

56 session.commit() 

57 

58 

59def downgrade(): 

60 """Performs DB downgrade removing revert_to_snapshot_support. 

61 

62 Remove attribute 'revert_to_snapshot_support' from Share model. 

63 """ 

64 

65 op.drop_column('shares', 'revert_to_snapshot_support')