1 """Add work queue name to runs
2
3 Revision ID: 575634b7acd4
4 Revises: 296e2665785f
5 Create Date: 2022-08-07 13:41:38.128173
6
7 """
8
9 import sqlalchemy as sa 1 ctx 1a
10 from alembic import op 1 ctx 1a
11
12 # revision identifiers, used by Alembic.
13 revision = "575634b7acd4" 1 ctx 1a
14 down_revision = "296e2665785f" 1 ctx 1a
15 branch_labels = None 1 ctx 1a
16 depends_on = None 1 ctx 1a
17
18
19 def upgrade ( ) : 1 ctx 1a
20 with op . batch_alter_table ( "deployment" , schema = None ) as batch_op : 1 ctx 1a
21 batch_op . add_column ( sa . Column ( "work_queue_name" , sa . String ( ) , nullable = True ) ) 1 ctx 1a
22 batch_op . create_index ( 1 ctx 1a
23 batch_op . f ( "ix_deployment__work_queue_name" ) ,
24 [ "work_queue_name" ] ,
25 unique = False ,
26 )
27
28 with op . batch_alter_table ( "flow_run" , schema = None ) as batch_op : 1 ctx 1a
29 batch_op . add_column ( sa . Column ( "work_queue_name" , sa . String ( ) , nullable = True ) ) 1 ctx 1a
30 batch_op . create_index ( 1 ctx 1a
31 batch_op . f ( "ix_flow_run__work_queue_name" ) ,
32 [ "work_queue_name" ] ,
33 unique = False ,
34 )
35
36 with op . batch_alter_table ( "work_queue" , schema = None ) as batch_op : 1 ctx 1a
37 batch_op . alter_column ( "filter" , nullable = True , server_default = None ) 1 ctx 1a
38
39
40 def downgrade ( ) : 1 ctx 1a
41 op . execute (
42 """
43 UPDATE work_queue
44 SET filter = '{}'
45 WHERE filter IS NULL;
46 """
47 )
48
49 with op . batch_alter_table ( "work_queue" , schema = None ) as batch_op :
50 batch_op . alter_column ( "filter" , nullable = False , server_default = sa . text ( "'{}'" ) )
51
52 with op . batch_alter_table ( "flow_run" , schema = None ) as batch_op :
53 batch_op . drop_index ( batch_op . f ( "ix_flow_run__work_queue_name" ) )
54 batch_op . drop_column ( "work_queue_name" )
55
56 with op . batch_alter_table ( "deployment" , schema = None ) as batch_op :
57 batch_op . drop_index ( batch_op . f ( "ix_deployment__work_queue_name" ) )
58 batch_op . drop_column ( "work_queue_name" )