Coverage for /usr/local/lib/python3.12/site-packages/prefect/server/database/_migrations/versions/sqlite/2022_07_19_153432_628a873f0d1a_renames_existing_block_types.py: 96%

19 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 11:21 +0000

1"""Renames existing block types and deletes removed block types 

2 

3Revision ID: 628a873f0d1a 

4Revises: 061c7e518b40 

5Create Date: 2022-07-19 15:34:32.619181 

6 

7""" 

8 

9import sqlalchemy as sa 1a

10from alembic import op 1a

11 

12# revision identifiers, used by Alembic. 

13revision = "628a873f0d1a" 1a

14down_revision = "56be24fdb383" 1a

15branch_labels = None 1a

16depends_on = None 1a

17 

18BLOCK_TYPES_TO_RENAME = [ 1a

19 {"OLD_NAME": "DateTime", "NEW_NAME": "Date Time"}, 

20 {"OLD_NAME": "EnvironmentVariable", "NEW_NAME": "Environment Variable"}, 

21 {"OLD_NAME": "KubernetesClusterConfig", "NEW_NAME": "Kubernetes Cluster Config"}, 

22 {"OLD_NAME": "LocalFileSystem", "NEW_NAME": "Local File System"}, 

23 {"OLD_NAME": "RemoteFileSystem", "NEW_NAME": "Remote File System"}, 

24] 

25 

26BLOCK_TYPES_TO_REMOVE = [ 1a

27 "Azure Blob Storage", 

28 "File Storage", 

29 "Google Cloud Storage", 

30 "KV Server Storage", 

31 "Local Storage", 

32 "S3 Storage", 

33 "Temporary Local Storage", 

34] 

35 

36 

37def upgrade(): 1a

38 connection = op.get_bind() 1a

39 meta_data = sa.MetaData() 1a

40 meta_data.reflect(connection) 1a

41 BLOCK_TYPE = meta_data.tables["block_type"] 1a

42 

43 for block_type_rename_config in BLOCK_TYPES_TO_RENAME: 1a

44 connection.execute( 1a

45 sa.update(BLOCK_TYPE) 

46 .where(BLOCK_TYPE.c.name == block_type_rename_config["OLD_NAME"]) 

47 .values(name=block_type_rename_config["NEW_NAME"]) 

48 ) 

49 for block_type_name in BLOCK_TYPES_TO_REMOVE: 1a

50 connection.execute( 1a

51 sa.delete(BLOCK_TYPE).where(BLOCK_TYPE.c.name == block_type_name) 

52 ) 

53 

54 

55def downgrade(): 1a

56 # Purely a data migration. No downgrade necessary. 

57 pass