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

23 statements  

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

1"""Update deployments to include more information 

2 

3Revision ID: 88c2112b668f 

4Revises: f335f9633eec 

5Create Date: 2022-07-25 13:10:28.849740 

6 

7""" 

8 

9import sqlalchemy as sa 1a

10from alembic import op 1a

11 

12import prefect 1a

13 

14# revision identifiers, used by Alembic. 

15revision = "88c2112b668f" 1a

16down_revision = "f335f9633eec" 1a

17branch_labels = None 1a

18depends_on = None 1a

19 

20 

21def upgrade(): 1a

22 op.add_column("deployment", sa.Column("manifest_path", sa.String(), nullable=True)) 1a

23 # any existing deployment is broken by these changes 

24 # set manifest path to an empty string 

25 # and turn the schedule off 

26 op.execute(sa.text("UPDATE deployment SET manifest_path = '';")) 1a

27 op.execute(sa.text("UPDATE deployment SET is_schedule_active = False;")) 1a

28 op.add_column( 1a

29 "deployment", 

30 sa.Column( 

31 "parameter_openapi_schema", 

32 prefect.server.utilities.database.JSON(), 

33 nullable=True, 

34 ), 

35 ) 

36 

37 op.execute("PRAGMA foreign_keys=OFF") 1a

38 with op.batch_alter_table("deployment", schema=None) as batch_op: 1a

39 batch_op.add_column( 1a

40 sa.Column( 

41 "storage_document_id", 

42 prefect.server.utilities.database.UUID(), 

43 nullable=True, 

44 ) 

45 ) 

46 batch_op.create_foreign_key( 1a

47 batch_op.f("fk_deployment__storage_document_id__block_document"), 

48 "block_document", 

49 ["storage_document_id"], 

50 ["id"], 

51 ondelete="CASCADE", 

52 ) 

53 op.execute("PRAGMA foreign_keys=ON") 1a

54 

55 

56def downgrade(): 1a

57 with op.batch_alter_table("deployment", schema=None) as batch_op: 

58 batch_op.drop_column("manifest_path") 

59 batch_op.drop_column("parameter_openapi_schema") 

60 batch_op.drop_constraint( 

61 batch_op.f("fk_deployment__storage_document_id__block_document"), 

62 type_="foreignkey", 

63 ) 

64 batch_op.drop_column("storage_document_id")