Coverage for manila/db/migrations/alembic/versions/bb5938d74b73_add_snapshot_metadata_table.py: 73%

22 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_snapshot_metadata_table 

14 

15Revision ID: bb5938d74b73 

16Revises: a87e0fb17dee 

17Create Date: 2022-01-14 14:36:59.408638 

18 

19""" 

20 

21# revision identifiers, used by Alembic. 

22revision = 'bb5938d74b73' 

23down_revision = 'a87e0fb17dee' 

24 

25from alembic import op 

26from oslo_log import log 

27import sqlalchemy as sql 

28 

29LOG = log.getLogger(__name__) 

30 

31share_snapshot_metadata_table_name = 'share_snapshot_metadata' 

32 

33 

34def upgrade(): 

35 context = op.get_context() 

36 mysql_dl = context.bind.dialect.name == 'mysql' 

37 datetime_type = (sql.dialects.mysql.DATETIME(fsp=6) 

38 if mysql_dl else sql.DateTime) 

39 try: 

40 op.create_table( 

41 share_snapshot_metadata_table_name, 

42 sql.Column('deleted', sql.String(36), default='False'), 

43 sql.Column('created_at', datetime_type), 

44 sql.Column('updated_at', datetime_type), 

45 sql.Column('deleted_at', datetime_type), 

46 sql.Column('share_snapshot_id', sql.String(36), 

47 sql.ForeignKey('share_snapshots.id'), nullable=False), 

48 sql.Column('key', sql.String(255), nullable=False), 

49 sql.Column('value', sql.String(1023), nullable=False), 

50 sql.Column('id', sql.Integer, primary_key=True, nullable=False), 

51 mysql_engine='InnoDB', 

52 mysql_charset='utf8' 

53 ) 

54 except Exception: 

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

56 share_snapshot_metadata_table_name) 

57 raise 

58 

59 

60def downgrade(): 

61 try: 

62 op.drop_table(share_snapshot_metadata_table_name) 

63 except Exception: 

64 LOG.error("Table |%s| not dropped!", 

65 share_snapshot_metadata_table_name) 

66 raise