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

19 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"""Change the datetime precision for all objects (MySQL and derivatives) 

14 

15Revision ID: fbdfabcba377 

16Revises: 478c445d8d3e 

17Create Date: 2020-04-20 15:32:59.365323 

18 

19""" 

20 

21# revision identifiers, used by Alembic. 

22revision = 'fbdfabcba377' 

23down_revision = '478c445d8d3e' 

24 

25from alembic import op 

26from sqlalchemy import DateTime, dialects 

27 

28 

29# DB Tables that can be affected by low precision timestamps in MySQL: 

30TABLES = ('services', 'quotas', 'project_user_quotas', 'backend_info', 

31 'project_share_type_quotas', 'quota_classes', 'quota_usages', 

32 'reservations', 'shares', 'share_instance_export_locations', 

33 'share_instances', 'share_instance_export_locations_metadata', 

34 'share_types', 'share_type_projects', 'share_type_extra_specs', 

35 'share_metadata', 'share_access_map', 'share_access_rules_metadata', 

36 'share_instance_access_map', 'share_snapshot_instances', 

37 'share_snapshots', 'share_snapshot_access_map', 'share_networks', 

38 'share_snapshot_instance_access_map', 'share_network_subnets', 

39 'share_snapshot_instance_export_locations', 'security_services', 

40 'share_servers', 'share_server_backend_details', 'share_groups', 

41 'network_allocations', 'share_network_security_service_association', 

42 'drivers_private_data', 'availability_zones', 'share_group_types', 

43 'share_group_type_projects', 'share_group_type_specs', 'messages', 

44 'share_group_snapshots', 'share_group_type_share_type_mappings', 

45 'share_group_share_type_mappings') 

46 

47 

48def upgrade(): 

49 context = op.get_context() 

50 

51 if context.bind.dialect.name == 'mysql': 

52 # override the default precision of DateTime: 

53 for table in TABLES: 

54 op.alter_column(table, 'created_at', 

55 existing_type=DateTime, 

56 type_=dialects.mysql.DATETIME(fsp=6)) 

57 op.alter_column(table, 'updated_at', 

58 existing_type=DateTime, 

59 type_=dialects.mysql.DATETIME(fsp=6)) 

60 op.alter_column(table, 'deleted_at', 

61 existing_type=DateTime, 

62 type_=dialects.mysql.DATETIME(fsp=6)) 

63 

64 

65def downgrade(): 

66 context = op.get_context() 

67 

68 if context.bind.dialect.name == 'mysql': 

69 for table in TABLES: 

70 op.alter_column(table, 'created_at', 

71 existing_type=dialects.mysql.DATETIME(fsp=6), 

72 type_=DateTime) 

73 op.alter_column(table, 'updated_at', 

74 existing_type=dialects.mysql.DATETIME(fsp=6), 

75 type_=DateTime) 

76 op.alter_column(table, 'deleted_at', 

77 existing_type=dialects.mysql.DATETIME(fsp=6), 

78 type_=DateTime)