Coverage for manila/db/migrations/alembic/versions/cb20f743ca7b_add_resource_locks.py: 71%

21 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_resource_locks 

14 

15Revision ID: cb20f743ca7b 

16Revises: 9afbe2df4945 

17Create Date: 2023-06-23 16:34:36.277477 

18 

19""" 

20 

21# revision identifiers, used by Alembic. 

22revision = 'cb20f743ca7b' 

23down_revision = '9afbe2df4945' 

24 

25from alembic import op 

26from oslo_log import log 

27import sqlalchemy as sa 

28 

29LOG = log.getLogger(__name__) 

30 

31 

32def upgrade(): 

33 context = op.get_context() 

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

35 datetime_type = (sa.dialects.mysql.DATETIME(fsp=6) 

36 if mysql_dl else sa.DateTime) 

37 try: 

38 op.create_table( 

39 'resource_locks', 

40 sa.Column('id', sa.String(36), primary_key=True, nullable=False), 

41 sa.Column('user_id', sa.String(255), nullable=False), 

42 sa.Column('project_id', sa.String(255), nullable=False), 

43 sa.Column('resource_action', sa.String(255), default='delete'), 

44 sa.Column('resource_type', sa.String(255), nullable=False), 

45 sa.Column('resource_id', sa.String(36), nullable=False), 

46 sa.Column('lock_context', sa.String(16), nullable=False), 

47 sa.Column('lock_reason', sa.String(1023), nullable=True), 

48 sa.Column('created_at', datetime_type), 

49 sa.Column('updated_at', datetime_type), 

50 sa.Column('deleted_at', datetime_type), 

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

52 mysql_engine='InnoDB', 

53 mysql_charset='utf8', 

54 ) 

55 except Exception: 

56 LOG.error("Table resource_locks not created!") 

57 raise 

58 

59 

60def downgrade(): 

61 try: 

62 op.drop_table('resource_locks') 

63 except Exception: 

64 LOG.error("resource_locks table not dropped") 

65 raise