1 """Add flow run alert policies
2
3 Revision ID: 888a0bb0df7b
4 Revises: b75d279ba985
5 Create Date: 2022-05-12 20:31:58.658936
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 = "888a0bb0df7b" 1 ctx 1a
16 down_revision = "b75d279ba985" 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 # ### commands auto generated by Alembic - please adjust! ###
23 op . create_table ( 1 ctx 1a
24 "flow_run_alert_queue" ,
25 sa . Column (
26 "id" ,
27 prefect . server . utilities . database . UUID ( ) ,
28 server_default = sa . text (
29 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
30 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
31 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
32 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
33 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
34 " lower(hex(randomblob(6)))\n )\n )"
35 ) ,
36 nullable = False ,
37 ) ,
38 sa . Column (
39 "created" ,
40 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
41 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
42 nullable = False ,
43 ) ,
44 sa . Column (
45 "updated" ,
46 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
47 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
48 nullable = False ,
49 ) ,
50 sa . Column (
51 "flow_run_alert_policy_id" ,
52 prefect . server . utilities . database . UUID ( ) ,
53 nullable = False ,
54 ) ,
55 sa . Column (
56 "flow_run_state_id" ,
57 prefect . server . utilities . database . UUID ( ) ,
58 nullable = False ,
59 ) ,
60 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_flow_run_alert_queue" ) ) ,
61 )
62 op . create_index ( 1 ctx 1a
63 op . f ( "ix_flow_run_alert_queue__updated" ) ,
64 "flow_run_alert_queue" ,
65 [ "updated" ] ,
66 unique = False ,
67 )
68 op . create_table ( 1 ctx 1a
69 "flow_run_alert_policy" ,
70 sa . Column (
71 "id" ,
72 prefect . server . utilities . database . UUID ( ) ,
73 server_default = sa . text (
74 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
75 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
76 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
77 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
78 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
79 " lower(hex(randomblob(6)))\n )\n )"
80 ) ,
81 nullable = False ,
82 ) ,
83 sa . Column (
84 "created" ,
85 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
86 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
87 nullable = False ,
88 ) ,
89 sa . Column (
90 "updated" ,
91 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
92 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
93 nullable = False ,
94 ) ,
95 sa . Column ( "name" , sa . String ( ) , nullable = False ) ,
96 sa . Column ( "is_active" , sa . Boolean ( ) , server_default = "1" , nullable = False ) ,
97 sa . Column (
98 "state_names" ,
99 prefect . server . utilities . database . JSON ( astext_type = sa . Text ( ) ) ,
100 server_default = "[]" ,
101 nullable = False ,
102 ) ,
103 sa . Column (
104 "tags" ,
105 prefect . server . utilities . database . JSON ( astext_type = sa . Text ( ) ) ,
106 server_default = "[]" ,
107 nullable = False ,
108 ) ,
109 sa . Column ( "message_template" , sa . String ( ) , nullable = True ) ,
110 sa . Column (
111 "block_document_id" ,
112 prefect . server . utilities . database . UUID ( ) ,
113 nullable = False ,
114 ) ,
115 sa . ForeignKeyConstraint (
116 [ "block_document_id" ] ,
117 [ "block_document.id" ] ,
118 name = op . f ( "fk_flow_run_alert_policy__block_document_id__block_document" ) ,
119 ondelete = "cascade" ,
120 ) ,
121 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_flow_run_alert" ) ) ,
122 )
123 op . create_index ( 1 ctx 1a
124 op . f ( "ix_flow_run_alert_policy__name" ) ,
125 "flow_run_alert_policy" ,
126 [ "name" ] ,
127 unique = False ,
128 )
129 op . create_index ( 1 ctx 1a
130 op . f ( "ix_flow_run_alert_policy__updated" ) ,
131 "flow_run_alert_policy" ,
132 [ "updated" ] ,
133 unique = False ,
134 )
135 # ### end Alembic commands ###
136
137
138 def downgrade ( ) : 1 ctx 1a
139 # ### commands auto generated by Alembic - please adjust! ###
140 op . drop_index (
141 op . f ( "ix_flow_run_alert_policy__name" ) ,
142 table_name = "flow_run_alert_policy" ,
143 )
144 op . drop_index (
145 op . f ( "ix_flow_run_alert_policy__updated" ) ,
146 table_name = "flow_run_alert_policy" ,
147 )
148 op . drop_table ( "flow_run_alert_policy" )
149 op . drop_index (
150 op . f ( "ix_flow_run_alert_queue__updated" ) ,
151 table_name = "flow_run_alert_queue" ,
152 )
153 op . drop_table ( "flow_run_alert_queue" )
154 # ### end Alembic commands ###