1 """Update deployments to include more information
2
3 Revision ID: 88c2112b668f
4 Revises: f335f9633eec
5 Create Date: 2022-07-25 13:10:28.849740
6
7 """
8
9 import sqlalchemy as sa 1 ctx 1a
10 from alembic import op 1 ctx 1a
11
12 import prefect 1 ctx 1a
13
14 # revision identifiers, used by Alembic.
15 revision = "88c2112b668f" 1 ctx 1a
16 down_revision = "f335f9633eec" 1 ctx 1a
17 branch_labels = None 1 ctx 1a
18 depends_on = None 1 ctx 1a
19
20
21 def upgrade ( ) : 1 ctx 1a
22 op . add_column ( "deployment" , sa . Column ( "manifest_path" , sa . String ( ) , nullable = True ) ) 1 ctx 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 = '';" ) ) 1 ctx 1a
27 op . execute ( sa . text ( "UPDATE deployment SET is_schedule_active = False;" ) ) 1 ctx 1a
28 op . add_column ( 1 ctx 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" ) 1 ctx 1a
38 with op . batch_alter_table ( "deployment" , schema = None ) as batch_op : 1 ctx 1a
39 batch_op . add_column ( 1 ctx 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 ( 1 ctx 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" ) 1 ctx 1a
54
55
56 def downgrade ( ) : 1 ctx 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" )