1 """Rename run alerts to run notifications
2
3 Revision ID: d76326ed0d06
4 Revises: 33439667aeea
5 Create Date: 2022-05-30 10:08:55.886326
6
7 """
8
9 from alembic import op 1 ctx 1a
10
11 # revision identifiers, used by Alembic.
12 revision = "d76326ed0d06" 1 ctx 1a
13 down_revision = "e73c6f1fe752" 1 ctx 1a
14 branch_labels = None 1 ctx 1a
15 depends_on = None 1 ctx 1a
16
17
18 def upgrade ( ) : 1 ctx 1a
19 # policy table
20 op . rename_table ( "flow_run_alert_policy" , "flow_run_notification_policy" ) 1 ctx 1a
21 with op . batch_alter_table ( "flow_run_notification_policy" ) as batch_op : 1 ctx 1a
22 batch_op . drop_index ( "ix_flow_run_alert_policy__name" ) 1 ctx 1a
23 batch_op . create_index ( 1 ctx 1a
24 op . f ( "ix_flow_run_notification_policy__name" ) ,
25 [ "name" ] ,
26 unique = False ,
27 )
28 batch_op . drop_index ( "ix_flow_run_alert_policy__updated" ) 1 ctx 1a
29 batch_op . create_index ( 1 ctx 1a
30 op . f ( "ix_flow_run_notification_policy__updated" ) ,
31 [ "updated" ] ,
32 unique = False ,
33 )
34 batch_op . drop_constraint ( "pk_flow_run_alert" ) 1 ctx 1a
35 batch_op . create_primary_key ( "pk_flow_run_notification_policy" , [ "id" ] ) 1 ctx 1a
36
37 # queue table
38 op . rename_table ( "flow_run_alert_queue" , "flow_run_notification_queue" ) 1 ctx 1a
39 with op . batch_alter_table ( "flow_run_notification_queue" ) as batch_op : 1 ctx 1a
40 batch_op . alter_column ( 1 ctx 1a
41 "flow_run_alert_policy_id" ,
42 new_column_name = "flow_run_notification_policy_id" ,
43 )
44 batch_op . drop_index ( "ix_flow_run_alert_queue__updated" ) 1 ctx 1a
45 batch_op . create_index ( 1 ctx 1a
46 op . f ( "ix_flow_run_notification_queue__updated" ) ,
47 [ "updated" ] ,
48 unique = False ,
49 )
50 batch_op . drop_constraint ( "pk_flow_run_alert_queue" ) 1 ctx 1a
51 batch_op . create_primary_key ( "pk_flow_run_notification_queue" , [ "id" ] ) 1 ctx 1a
52
53
54 def downgrade ( ) : 1 ctx 1a
55 # queue table
56 op . rename_table ( "flow_run_notification_queue" , "flow_run_alert_queue" )
57 with op . batch_alter_table ( "flow_run_alert_queue" ) as batch_op :
58 batch_op . alter_column (
59 "flow_run_notification_policy_id" ,
60 new_column_name = "flow_run_alert_policy_id" ,
61 )
62 batch_op . drop_index ( "ix_flow_run_notification_queue__updated" )
63 batch_op . create_index (
64 op . f ( "ix_flow_run_alert_queue__updated" ) ,
65 [ "updated" ] ,
66 unique = False ,
67 )
68 batch_op . drop_constraint ( "pk_flow_run_notification_queue" )
69 batch_op . create_primary_key ( "pk_flow_run_alert_queue" , [ "id" ] )
70
71 # policy table
72 op . rename_table ( "flow_run_notification_policy" , "flow_run_alert_policy" )
73 with op . batch_alter_table ( "flow_run_alert_policy" ) as batch_op :
74 batch_op . drop_index ( "ix_flow_run_notification_policy__name" )
75 batch_op . create_index (
76 op . f ( "ix_flow_run_alert_policy__name" ) ,
77 [ "name" ] ,
78 unique = False ,
79 )
80 batch_op . drop_index ( "ix_flow_run_notification_policy__updated" )
81 batch_op . create_index (
82 op . f ( "ix_flow_run_alert_policy__updated" ) ,
83 [ "updated" ] ,
84 unique = False ,
85 )
86 batch_op . drop_constraint ( "pk_flow_run_notification_policy" )
87 batch_op . create_primary_key ( "pk_flow_run_alert" , [ "id" ] )