1 """initial migration
2
3 Revision ID: 9725c1cbee35
4 Revises:
5 Create Date: 2022-01-20 11:52:36.295433
6
7 """
8
9 from typing import Dict , List , Union 1 ctx 1a
10
11 import sqlalchemy as sa 1 ctx 1a
12 from alembic import op 1 ctx 1a
13 from sqlalchemy import Text 1 ctx 1a
14
15 import prefect 1 ctx 1a
16 from prefect . server . utilities . schemas import PrefectBaseModel 1 ctx 1a
17
18
19 class DataDocument ( PrefectBaseModel ) : 1 ctx 1a
20 """
21 DataDocuments were deprecated in September 2022 and this stub is included here
22 to simplify removal from the library.
23 """
24
25 encoding : str 1 ctx 1a
26 blob : bytes 1 ctx 1a
27
28
29 # revision identifiers, used by Alembic.
30 revision = "9725c1cbee35" 1 ctx 1a
31 down_revision = None 1 ctx 1a
32 branch_labels = None 1 ctx 1a
33 depends_on = None 1 ctx 1a
34
35
36 def upgrade ( ) : 1 ctx 1a
37 # Create tables
38 op . create_table ( 1 ctx 1a
39 "flow" ,
40 sa . Column (
41 "id" ,
42 prefect . server . utilities . database . UUID ( ) ,
43 server_default = sa . text (
44 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
45 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
46 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
47 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
48 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
49 " lower(hex(randomblob(6)))\n )\n )"
50 ) ,
51 nullable = False ,
52 ) ,
53 sa . Column (
54 "created" ,
55 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
56 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
57 nullable = False ,
58 ) ,
59 sa . Column (
60 "updated" ,
61 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
62 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
63 nullable = False ,
64 ) ,
65 sa . Column ( "name" , sa . String ( ) , nullable = False ) ,
66 sa . Column (
67 "tags" ,
68 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
69 server_default = "[]" ,
70 nullable = False ,
71 ) ,
72 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_flow" ) ) ,
73 sa . UniqueConstraint ( "name" , name = op . f ( "uq_flow__name" ) ) ,
74 )
75 op . create_index ( op . f ( "ix_flow__updated" ) , "flow" , [ "updated" ] , unique = False ) 1 ctx 1a
76 op . create_table ( 1 ctx 1a
77 "log" ,
78 sa . Column (
79 "id" ,
80 prefect . server . utilities . database . UUID ( ) ,
81 server_default = sa . text (
82 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
83 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
84 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
85 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
86 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
87 " lower(hex(randomblob(6)))\n )\n )"
88 ) ,
89 nullable = False ,
90 ) ,
91 sa . Column (
92 "created" ,
93 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
94 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
95 nullable = False ,
96 ) ,
97 sa . Column (
98 "updated" ,
99 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
100 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
101 nullable = False ,
102 ) ,
103 sa . Column ( "name" , sa . String ( ) , nullable = False ) ,
104 sa . Column ( "level" , sa . SmallInteger ( ) , nullable = False ) ,
105 sa . Column (
106 "flow_run_id" , prefect . server . utilities . database . UUID ( ) , nullable = False
107 ) ,
108 sa . Column (
109 "task_run_id" , prefect . server . utilities . database . UUID ( ) , nullable = True
110 ) ,
111 sa . Column ( "message" , sa . Text ( ) , nullable = False ) ,
112 sa . Column (
113 "timestamp" ,
114 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
115 nullable = False ,
116 ) ,
117 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_log" ) ) ,
118 )
119 op . create_index ( op . f ( "ix_log__flow_run_id" ) , "log" , [ "flow_run_id" ] , unique = False ) 1 ctx 1a
120 op . create_index ( op . f ( "ix_log__level" ) , "log" , [ "level" ] , unique = False ) 1 ctx 1a
121 op . create_index ( op . f ( "ix_log__task_run_id" ) , "log" , [ "task_run_id" ] , unique = False ) 1 ctx 1a
122 op . create_index ( op . f ( "ix_log__timestamp" ) , "log" , [ "timestamp" ] , unique = False ) 1 ctx 1a
123 op . create_index ( op . f ( "ix_log__updated" ) , "log" , [ "updated" ] , unique = False ) 1 ctx 1a
124 op . create_table ( 1 ctx 1a
125 "concurrency_limit" ,
126 sa . Column (
127 "id" ,
128 prefect . server . utilities . database . UUID ( ) ,
129 server_default = sa . text (
130 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
131 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
132 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
133 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
134 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
135 " lower(hex(randomblob(6)))\n )\n )"
136 ) ,
137 nullable = False ,
138 ) ,
139 sa . Column (
140 "created" ,
141 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
142 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
143 nullable = False ,
144 ) ,
145 sa . Column (
146 "updated" ,
147 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
148 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
149 nullable = False ,
150 ) ,
151 sa . Column ( "tag" , sa . String ( ) , nullable = False ) ,
152 sa . Column ( "concurrency_limit" , sa . Integer ( ) , nullable = False ) ,
153 sa . Column (
154 "active_slots" ,
155 prefect . server . utilities . database . JSON ( astext_type = sa . Text ( ) ) ,
156 server_default = "[]" ,
157 nullable = False ,
158 ) ,
159 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_concurrency_limit" ) ) ,
160 )
161 op . create_index ( 1 ctx 1a
162 op . f ( "ix_concurrency_limit__tag" ) , "concurrency_limit" , [ "tag" ] , unique = True
163 )
164 op . create_index ( 1 ctx 1a
165 op . f ( "ix_concurrency_limit__updated" ) ,
166 "concurrency_limit" ,
167 [ "updated" ] ,
168 unique = False ,
169 )
170 op . create_table ( 1 ctx 1a
171 "saved_search" ,
172 sa . Column (
173 "id" ,
174 prefect . server . utilities . database . UUID ( ) ,
175 server_default = sa . text (
176 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
177 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
178 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
179 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
180 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
181 " lower(hex(randomblob(6)))\n )\n )"
182 ) ,
183 nullable = False ,
184 ) ,
185 sa . Column (
186 "created" ,
187 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
188 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
189 nullable = False ,
190 ) ,
191 sa . Column (
192 "updated" ,
193 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
194 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
195 nullable = False ,
196 ) ,
197 sa . Column ( "name" , sa . String ( ) , nullable = False ) ,
198 sa . Column (
199 "filters" ,
200 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
201 server_default = "[]" ,
202 nullable = False ,
203 ) ,
204 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_saved_search" ) ) ,
205 sa . UniqueConstraint ( "name" , name = op . f ( "uq_saved_search__name" ) ) ,
206 )
207 op . create_index ( 1 ctx 1a
208 op . f ( "ix_saved_search__updated" ) , "saved_search" , [ "updated" ] , unique = False
209 )
210 op . create_table ( 1 ctx 1a
211 "task_run_state_cache" ,
212 sa . Column (
213 "id" ,
214 prefect . server . utilities . database . UUID ( ) ,
215 server_default = sa . text (
216 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
217 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
218 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
219 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
220 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
221 " lower(hex(randomblob(6)))\n )\n )"
222 ) ,
223 nullable = False ,
224 ) ,
225 sa . Column (
226 "created" ,
227 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
228 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
229 nullable = False ,
230 ) ,
231 sa . Column (
232 "updated" ,
233 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
234 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
235 nullable = False ,
236 ) ,
237 sa . Column ( "cache_key" , sa . String ( ) , nullable = False ) ,
238 sa . Column (
239 "cache_expiration" ,
240 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
241 nullable = True ,
242 ) ,
243 sa . Column (
244 "task_run_state_id" ,
245 prefect . server . utilities . database . UUID ( ) ,
246 nullable = False ,
247 ) ,
248 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_task_run_state_cache" ) ) ,
249 )
250 op . create_index ( 1 ctx 1a
251 "ix_task_run_state_cache__cache_key_created_desc" ,
252 "task_run_state_cache" ,
253 [ "cache_key" , sa . text ( "created DESC" ) ] ,
254 unique = False ,
255 )
256 op . create_index ( 1 ctx 1a
257 op . f ( "ix_task_run_state_cache__updated" ) ,
258 "task_run_state_cache" ,
259 [ "updated" ] ,
260 unique = False ,
261 )
262 op . create_table ( 1 ctx 1a
263 "deployment" ,
264 sa . Column (
265 "id" ,
266 prefect . server . utilities . database . UUID ( ) ,
267 server_default = sa . text (
268 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
269 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
270 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
271 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
272 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
273 " lower(hex(randomblob(6)))\n )\n )"
274 ) ,
275 nullable = False ,
276 ) ,
277 sa . Column (
278 "created" ,
279 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
280 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
281 nullable = False ,
282 ) ,
283 sa . Column (
284 "updated" ,
285 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
286 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
287 nullable = False ,
288 ) ,
289 sa . Column ( "name" , sa . String ( ) , nullable = False ) ,
290 sa . Column (
291 "schedule" ,
292 prefect . server . utilities . database . Pydantic (
293 prefect . server . schemas . schedules . SCHEDULE_TYPES
294 ) ,
295 nullable = True ,
296 ) ,
297 sa . Column (
298 "is_schedule_active" , sa . Boolean ( ) , server_default = "1" , nullable = False
299 ) ,
300 sa . Column (
301 "tags" ,
302 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
303 server_default = "[]" ,
304 nullable = False ,
305 ) ,
306 sa . Column (
307 "parameters" ,
308 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
309 server_default = "{}" ,
310 nullable = False ,
311 ) ,
312 sa . Column (
313 "flow_data" ,
314 prefect . server . utilities . database . Pydantic ( DataDocument ) ,
315 nullable = True ,
316 ) ,
317 sa . Column ( "flow_runner_type" , sa . String ( ) , nullable = True ) ,
318 sa . Column (
319 "flow_runner_config" ,
320 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
321 nullable = True ,
322 ) ,
323 sa . Column ( "flow_id" , prefect . server . utilities . database . UUID ( ) , nullable = False ) ,
324 sa . ForeignKeyConstraint (
325 [ "flow_id" ] ,
326 [ "flow.id" ] ,
327 name = op . f ( "fk_deployment__flow_id__flow" ) ,
328 ondelete = "CASCADE" ,
329 ) ,
330 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_deployment" ) ) ,
331 )
332 op . create_index ( 1 ctx 1a
333 op . f ( "ix_deployment__flow_id" ) , "deployment" , [ "flow_id" ] , unique = False
334 )
335 op . create_index ( 1 ctx 1a
336 op . f ( "ix_deployment__updated" ) , "deployment" , [ "updated" ] , unique = False
337 )
338 op . create_index ( 1 ctx 1a
339 "uq_deployment__flow_id_name" , "deployment" , [ "flow_id" , "name" ] , unique = True
340 )
341 op . create_table ( 1 ctx 1a
342 "flow_run" ,
343 sa . Column (
344 "id" ,
345 prefect . server . utilities . database . UUID ( ) ,
346 server_default = sa . text (
347 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
348 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
349 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
350 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
351 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
352 " lower(hex(randomblob(6)))\n )\n )"
353 ) ,
354 nullable = False ,
355 ) ,
356 sa . Column (
357 "created" ,
358 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
359 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
360 nullable = False ,
361 ) ,
362 sa . Column (
363 "updated" ,
364 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
365 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
366 nullable = False ,
367 ) ,
368 sa . Column ( "name" , sa . String ( ) , nullable = False ) ,
369 sa . Column (
370 "state_type" ,
371 sa . Enum (
372 "SCHEDULED" ,
373 "PENDING" ,
374 "RUNNING" ,
375 "COMPLETED" ,
376 "FAILED" ,
377 "CANCELLED" ,
378 name = "state_type" ,
379 ) ,
380 nullable = True ,
381 ) ,
382 sa . Column ( "run_count" , sa . Integer ( ) , server_default = "0" , nullable = False ) ,
383 sa . Column (
384 "expected_start_time" ,
385 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
386 nullable = True ,
387 ) ,
388 sa . Column (
389 "next_scheduled_start_time" ,
390 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
391 nullable = True ,
392 ) ,
393 sa . Column (
394 "start_time" ,
395 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
396 nullable = True ,
397 ) ,
398 sa . Column (
399 "end_time" ,
400 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
401 nullable = True ,
402 ) ,
403 sa . Column ( "total_run_time" , sa . Interval ( ) , server_default = "0" , nullable = False ) ,
404 sa . Column ( "flow_version" , sa . String ( ) , nullable = True ) ,
405 sa . Column (
406 "parameters" ,
407 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
408 server_default = "{}" ,
409 nullable = False ,
410 ) ,
411 sa . Column ( "idempotency_key" , sa . String ( ) , nullable = True ) ,
412 sa . Column (
413 "context" ,
414 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
415 server_default = "{}" ,
416 nullable = False ,
417 ) ,
418 sa . Column (
419 "empirical_policy" ,
420 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
421 server_default = "{}" ,
422 nullable = False ,
423 ) ,
424 sa . Column (
425 "tags" ,
426 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
427 server_default = "[]" ,
428 nullable = False ,
429 ) ,
430 sa . Column ( "flow_runner_type" , sa . String ( ) , nullable = True ) ,
431 sa . Column (
432 "flow_runner_config" ,
433 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
434 nullable = True ,
435 ) ,
436 sa . Column (
437 "empirical_config" ,
438 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
439 server_default = "{}" ,
440 nullable = False ,
441 ) ,
442 sa . Column ( "auto_scheduled" , sa . Boolean ( ) , server_default = "0" , nullable = False ) ,
443 sa . Column ( "flow_id" , prefect . server . utilities . database . UUID ( ) , nullable = False ) ,
444 sa . Column (
445 "deployment_id" , prefect . server . utilities . database . UUID ( ) , nullable = True
446 ) ,
447 sa . Column (
448 "parent_task_run_id" ,
449 prefect . server . utilities . database . UUID ( ) ,
450 nullable = True ,
451 ) ,
452 sa . Column ( "state_id" , prefect . server . utilities . database . UUID ( ) , nullable = True ) ,
453 sa . ForeignKeyConstraint (
454 [ "deployment_id" ] ,
455 [ "deployment.id" ] ,
456 name = op . f ( "fk_flow_run__deployment_id__deployment" ) ,
457 ondelete = "set null" ,
458 ) ,
459 sa . ForeignKeyConstraint (
460 [ "flow_id" ] ,
461 [ "flow.id" ] ,
462 name = op . f ( "fk_flow_run__flow_id__flow" ) ,
463 ondelete = "cascade" ,
464 ) ,
465 sa . ForeignKeyConstraint (
466 [ "parent_task_run_id" ] ,
467 [ "task_run.id" ] ,
468 name = op . f ( "fk_flow_run__parent_task_run_id__task_run" ) ,
469 ondelete = "SET NULL" ,
470 use_alter = True ,
471 ) ,
472 sa . ForeignKeyConstraint (
473 [ "state_id" ] ,
474 [ "flow_run_state.id" ] ,
475 name = op . f ( "fk_flow_run__state_id__flow_run_state" ) ,
476 ondelete = "SET NULL" ,
477 use_alter = True ,
478 ) ,
479 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_flow_run" ) ) ,
480 )
481 op . create_index ( 1 ctx 1a
482 op . f ( "ix_flow_run__deployment_id" ) , "flow_run" , [ "deployment_id" ] , unique = False
483 )
484 op . create_index ( 1 ctx 1a
485 "ix_flow_run__end_time_desc" ,
486 "flow_run" ,
487 [ sa . text ( "end_time DESC" ) ] ,
488 unique = False ,
489 )
490 op . create_index ( 1 ctx 1a
491 "ix_flow_run__expected_start_time_desc" ,
492 "flow_run" ,
493 [ sa . text ( "expected_start_time DESC" ) ] ,
494 unique = False ,
495 )
496 op . create_index ( op . f ( "ix_flow_run__flow_id" ) , "flow_run" , [ "flow_id" ] , unique = False ) 1 ctx 1a
497 op . create_index ( 1 ctx 1a
498 op . f ( "ix_flow_run__flow_version" ) , "flow_run" , [ "flow_version" ] , unique = False
499 )
500 op . create_index ( op . f ( "ix_flow_run__name" ) , "flow_run" , [ "name" ] , unique = False ) 1 ctx 1a
501 op . create_index ( 1 ctx 1a
502 "ix_flow_run__next_scheduled_start_time_asc" ,
503 "flow_run" ,
504 [ sa . text ( "next_scheduled_start_time ASC" ) ] ,
505 unique = False ,
506 )
507 op . create_index ( 1 ctx 1a
508 op . f ( "ix_flow_run__parent_task_run_id" ) ,
509 "flow_run" ,
510 [ "parent_task_run_id" ] ,
511 unique = False ,
512 )
513 op . create_index ( "ix_flow_run__start_time" , "flow_run" , [ "start_time" ] , unique = False ) 1 ctx 1a
514 op . create_index ( 1 ctx 1a
515 op . f ( "ix_flow_run__state_id" ) , "flow_run" , [ "state_id" ] , unique = False
516 )
517 op . create_index ( "ix_flow_run__state_type" , "flow_run" , [ "state_type" ] , unique = False ) 1 ctx 1a
518 op . create_index ( op . f ( "ix_flow_run__updated" ) , "flow_run" , [ "updated" ] , unique = False ) 1 ctx 1a
519 op . create_index ( 1 ctx 1a
520 "uq_flow_run__flow_id_idempotency_key" ,
521 "flow_run" ,
522 [ "flow_id" , "idempotency_key" ] ,
523 unique = True ,
524 )
525 op . create_table ( 1 ctx 1a
526 "flow_run_state" ,
527 sa . Column (
528 "id" ,
529 prefect . server . utilities . database . UUID ( ) ,
530 server_default = sa . text (
531 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
532 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
533 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
534 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
535 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
536 " lower(hex(randomblob(6)))\n )\n )"
537 ) ,
538 nullable = False ,
539 ) ,
540 sa . Column (
541 "created" ,
542 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
543 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
544 nullable = False ,
545 ) ,
546 sa . Column (
547 "updated" ,
548 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
549 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
550 nullable = False ,
551 ) ,
552 sa . Column (
553 "type" ,
554 sa . Enum (
555 "SCHEDULED" ,
556 "PENDING" ,
557 "RUNNING" ,
558 "COMPLETED" ,
559 "FAILED" ,
560 "CANCELLED" ,
561 name = "state_type" ,
562 ) ,
563 nullable = False ,
564 ) ,
565 sa . Column (
566 "timestamp" ,
567 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
568 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
569 nullable = False ,
570 ) ,
571 sa . Column ( "name" , sa . String ( ) , nullable = False ) ,
572 sa . Column ( "message" , sa . String ( ) , nullable = True ) ,
573 sa . Column (
574 "state_details" ,
575 prefect . server . utilities . database . Pydantic (
576 prefect . server . schemas . states . StateDetails
577 ) ,
578 server_default = "{}" ,
579 nullable = False ,
580 ) ,
581 sa . Column (
582 "data" ,
583 prefect . server . utilities . database . Pydantic ( DataDocument ) ,
584 nullable = True ,
585 ) ,
586 sa . Column (
587 "flow_run_id" , prefect . server . utilities . database . UUID ( ) , nullable = False
588 ) ,
589 sa . ForeignKeyConstraint (
590 [ "flow_run_id" ] ,
591 [ "flow_run.id" ] ,
592 name = op . f ( "fk_flow_run_state__flow_run_id__flow_run" ) ,
593 ondelete = "cascade" ,
594 ) ,
595 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_flow_run_state" ) ) ,
596 )
597 op . create_index ( 1 ctx 1a
598 op . f ( "ix_flow_run_state__name" ) , "flow_run_state" , [ "name" ] , unique = False
599 )
600 op . create_index ( 1 ctx 1a
601 op . f ( "ix_flow_run_state__type" ) , "flow_run_state" , [ "type" ] , unique = False
602 )
603 op . create_index ( 1 ctx 1a
604 op . f ( "ix_flow_run_state__updated" ) , "flow_run_state" , [ "updated" ] , unique = False
605 )
606 op . create_index ( 1 ctx 1a
607 "uq_flow_run_state__flow_run_id_timestamp_desc" ,
608 "flow_run_state" ,
609 [ "flow_run_id" , sa . text ( "timestamp DESC" ) ] ,
610 unique = True ,
611 )
612 op . create_table ( 1 ctx 1a
613 "task_run" ,
614 sa . Column (
615 "id" ,
616 prefect . server . utilities . database . UUID ( ) ,
617 server_default = sa . text (
618 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
619 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
620 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
621 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
622 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
623 " lower(hex(randomblob(6)))\n )\n )"
624 ) ,
625 nullable = False ,
626 ) ,
627 sa . Column (
628 "created" ,
629 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
630 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
631 nullable = False ,
632 ) ,
633 sa . Column (
634 "updated" ,
635 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
636 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
637 nullable = False ,
638 ) ,
639 sa . Column ( "name" , sa . String ( ) , nullable = False ) ,
640 sa . Column (
641 "state_type" ,
642 sa . Enum (
643 "SCHEDULED" ,
644 "PENDING" ,
645 "RUNNING" ,
646 "COMPLETED" ,
647 "FAILED" ,
648 "CANCELLED" ,
649 name = "state_type" ,
650 ) ,
651 nullable = True ,
652 ) ,
653 sa . Column ( "run_count" , sa . Integer ( ) , server_default = "0" , nullable = False ) ,
654 sa . Column (
655 "expected_start_time" ,
656 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
657 nullable = True ,
658 ) ,
659 sa . Column (
660 "next_scheduled_start_time" ,
661 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
662 nullable = True ,
663 ) ,
664 sa . Column (
665 "start_time" ,
666 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
667 nullable = True ,
668 ) ,
669 sa . Column (
670 "end_time" ,
671 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
672 nullable = True ,
673 ) ,
674 sa . Column ( "total_run_time" , sa . Interval ( ) , server_default = "0" , nullable = False ) ,
675 sa . Column ( "task_key" , sa . String ( ) , nullable = False ) ,
676 sa . Column ( "dynamic_key" , sa . String ( ) , nullable = False ) ,
677 sa . Column ( "cache_key" , sa . String ( ) , nullable = True ) ,
678 sa . Column (
679 "cache_expiration" ,
680 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
681 nullable = True ,
682 ) ,
683 sa . Column ( "task_version" , sa . String ( ) , nullable = True ) ,
684 sa . Column (
685 "empirical_policy" ,
686 prefect . server . utilities . database . Pydantic (
687 prefect . server . schemas . core . TaskRunPolicy
688 ) ,
689 server_default = "{}" ,
690 nullable = False ,
691 ) ,
692 sa . Column (
693 "task_inputs" ,
694 prefect . server . utilities . database . Pydantic (
695 Dict [
696 str ,
697 List [
698 Union [
699 prefect . server . schemas . core . TaskRunResult ,
700 prefect . server . schemas . core . Parameter ,
701 prefect . server . schemas . core . Constant ,
702 ]
703 ] ,
704 ]
705 ) ,
706 server_default = "{}" ,
707 nullable = False ,
708 ) ,
709 sa . Column (
710 "tags" ,
711 prefect . server . utilities . database . JSON ( astext_type = Text ( ) ) ,
712 server_default = "[]" ,
713 nullable = False ,
714 ) ,
715 sa . Column (
716 "flow_run_id" , prefect . server . utilities . database . UUID ( ) , nullable = False
717 ) ,
718 sa . Column ( "state_id" , prefect . server . utilities . database . UUID ( ) , nullable = True ) ,
719 sa . ForeignKeyConstraint (
720 [ "flow_run_id" ] ,
721 [ "flow_run.id" ] ,
722 name = op . f ( "fk_task_run__flow_run_id__flow_run" ) ,
723 ondelete = "cascade" ,
724 ) ,
725 sa . ForeignKeyConstraint (
726 [ "state_id" ] ,
727 [ "task_run_state.id" ] ,
728 name = op . f ( "fk_task_run__state_id__task_run_state" ) ,
729 ondelete = "SET NULL" ,
730 use_alter = True ,
731 ) ,
732 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_task_run" ) ) ,
733 )
734 op . create_index ( 1 ctx 1a
735 "ix_task_run__end_time_desc" ,
736 "task_run" ,
737 [ sa . text ( "end_time DESC" ) ] ,
738 unique = False ,
739 )
740 op . create_index ( 1 ctx 1a
741 "ix_task_run__expected_start_time_desc" ,
742 "task_run" ,
743 [ sa . text ( "expected_start_time DESC" ) ] ,
744 unique = False ,
745 )
746 op . create_index ( 1 ctx 1a
747 op . f ( "ix_task_run__flow_run_id" ) , "task_run" , [ "flow_run_id" ] , unique = False
748 )
749 op . create_index ( op . f ( "ix_task_run__name" ) , "task_run" , [ "name" ] , unique = False ) 1 ctx 1a
750 op . create_index ( 1 ctx 1a
751 "ix_task_run__next_scheduled_start_time_asc" ,
752 "task_run" ,
753 [ sa . text ( "next_scheduled_start_time ASC" ) ] ,
754 unique = False ,
755 )
756 op . create_index ( "ix_task_run__start_time" , "task_run" , [ "start_time" ] , unique = False ) 1 ctx 1a
757 op . create_index ( 1 ctx 1a
758 op . f ( "ix_task_run__state_id" ) , "task_run" , [ "state_id" ] , unique = False
759 )
760 op . create_index ( "ix_task_run__state_type" , "task_run" , [ "state_type" ] , unique = False ) 1 ctx 1a
761 op . create_index ( op . f ( "ix_task_run__updated" ) , "task_run" , [ "updated" ] , unique = False ) 1 ctx 1a
762 op . create_index ( 1 ctx 1a
763 "uq_task_run__flow_run_id_task_key_dynamic_key" ,
764 "task_run" ,
765 [ "flow_run_id" , "task_key" , "dynamic_key" ] ,
766 unique = True ,
767 )
768 op . create_table ( 1 ctx 1a
769 "task_run_state" ,
770 sa . Column (
771 "id" ,
772 prefect . server . utilities . database . UUID ( ) ,
773 server_default = sa . text (
774 "(\n (\n lower(hex(randomblob(4))) \n || '-' \n "
775 " || lower(hex(randomblob(2))) \n || '-4' \n ||"
776 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
777 " substr('89ab',abs(random()) % 4 + 1, 1) \n ||"
778 " substr(lower(hex(randomblob(2))),2) \n || '-' \n ||"
779 " lower(hex(randomblob(6)))\n )\n )"
780 ) ,
781 nullable = False ,
782 ) ,
783 sa . Column (
784 "created" ,
785 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
786 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
787 nullable = False ,
788 ) ,
789 sa . Column (
790 "updated" ,
791 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
792 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
793 nullable = False ,
794 ) ,
795 sa . Column (
796 "type" ,
797 sa . Enum (
798 "SCHEDULED" ,
799 "PENDING" ,
800 "RUNNING" ,
801 "COMPLETED" ,
802 "FAILED" ,
803 "CANCELLED" ,
804 name = "state_type" ,
805 ) ,
806 nullable = False ,
807 ) ,
808 sa . Column (
809 "timestamp" ,
810 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
811 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
812 nullable = False ,
813 ) ,
814 sa . Column ( "name" , sa . String ( ) , nullable = False ) ,
815 sa . Column ( "message" , sa . String ( ) , nullable = True ) ,
816 sa . Column (
817 "state_details" ,
818 prefect . server . utilities . database . Pydantic (
819 prefect . server . schemas . states . StateDetails
820 ) ,
821 server_default = "{}" ,
822 nullable = False ,
823 ) ,
824 sa . Column (
825 "data" ,
826 prefect . server . utilities . database . Pydantic ( DataDocument ) ,
827 nullable = True ,
828 ) ,
829 sa . Column (
830 "task_run_id" , prefect . server . utilities . database . UUID ( ) , nullable = False
831 ) ,
832 sa . ForeignKeyConstraint (
833 [ "task_run_id" ] ,
834 [ "task_run.id" ] ,
835 name = op . f ( "fk_task_run_state__task_run_id__task_run" ) ,
836 ondelete = "cascade" ,
837 ) ,
838 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_task_run_state" ) ) ,
839 )
840 op . create_index ( 1 ctx 1a
841 op . f ( "ix_task_run_state__name" ) , "task_run_state" , [ "name" ] , unique = False
842 )
843 op . create_index ( 1 ctx 1a
844 op . f ( "ix_task_run_state__type" ) , "task_run_state" , [ "type" ] , unique = False
845 )
846 op . create_index ( 1 ctx 1a
847 op . f ( "ix_task_run_state__updated" ) , "task_run_state" , [ "updated" ] , unique = False
848 )
849 op . create_index ( 1 ctx 1a
850 "uq_task_run_state__task_run_id_timestamp_desc" ,
851 "task_run_state" ,
852 [ "task_run_id" , sa . text ( "timestamp DESC" ) ] ,
853 unique = True ,
854 )
855
856
857 def downgrade ( ) : 1 ctx 1a
858 # Drop tables
859 op . drop_index (
860 "uq_task_run_state__task_run_id_timestamp_desc" , table_name = "task_run_state"
861 )
862 op . drop_index ( op . f ( "ix_task_run_state__updated" ) , table_name = "task_run_state" )
863 op . drop_index ( op . f ( "ix_task_run_state__type" ) , table_name = "task_run_state" )
864 op . drop_index ( op . f ( "ix_task_run_state__name" ) , table_name = "task_run_state" )
865 op . drop_table ( "task_run_state" )
866 op . drop_index (
867 "uq_task_run__flow_run_id_task_key_dynamic_key" , table_name = "task_run"
868 )
869 op . drop_index ( op . f ( "ix_task_run__updated" ) , table_name = "task_run" )
870 op . drop_index ( "ix_task_run__state_type" , table_name = "task_run" )
871 op . drop_index ( op . f ( "ix_task_run__state_id" ) , table_name = "task_run" )
872 op . drop_index ( "ix_task_run__start_time" , table_name = "task_run" )
873 op . drop_index ( "ix_task_run__next_scheduled_start_time_asc" , table_name = "task_run" )
874 op . drop_index ( op . f ( "ix_task_run__name" ) , table_name = "task_run" )
875 op . drop_index ( op . f ( "ix_task_run__flow_run_id" ) , table_name = "task_run" )
876 op . drop_index ( "ix_task_run__expected_start_time_desc" , table_name = "task_run" )
877 op . drop_index ( "ix_task_run__end_time_desc" , table_name = "task_run" )
878 op . drop_table ( "task_run" )
879 op . drop_index (
880 "uq_flow_run_state__flow_run_id_timestamp_desc" , table_name = "flow_run_state"
881 )
882 op . drop_index ( op . f ( "ix_flow_run_state__updated" ) , table_name = "flow_run_state" )
883 op . drop_index ( op . f ( "ix_flow_run_state__type" ) , table_name = "flow_run_state" )
884 op . drop_index ( op . f ( "ix_flow_run_state__name" ) , table_name = "flow_run_state" )
885 op . drop_table ( "flow_run_state" )
886 op . drop_index ( "uq_flow_run__flow_id_idempotency_key" , table_name = "flow_run" )
887 op . drop_index ( op . f ( "ix_flow_run__updated" ) , table_name = "flow_run" )
888 op . drop_index ( "ix_flow_run__state_type" , table_name = "flow_run" )
889 op . drop_index ( op . f ( "ix_flow_run__state_id" ) , table_name = "flow_run" )
890 op . drop_index ( "ix_flow_run__start_time" , table_name = "flow_run" )
891 op . drop_index ( op . f ( "ix_flow_run__parent_task_run_id" ) , table_name = "flow_run" )
892 op . drop_index ( "ix_flow_run__next_scheduled_start_time_asc" , table_name = "flow_run" )
893 op . drop_index ( op . f ( "ix_flow_run__name" ) , table_name = "flow_run" )
894 op . drop_index ( op . f ( "ix_flow_run__flow_version" ) , table_name = "flow_run" )
895 op . drop_index ( op . f ( "ix_flow_run__flow_id" ) , table_name = "flow_run" )
896 op . drop_index ( "ix_flow_run__expected_start_time_desc" , table_name = "flow_run" )
897 op . drop_index ( "ix_flow_run__end_time_desc" , table_name = "flow_run" )
898 op . drop_index ( op . f ( "ix_flow_run__deployment_id" ) , table_name = "flow_run" )
899 op . drop_table ( "flow_run" )
900 op . drop_index ( "uq_deployment__flow_id_name" , table_name = "deployment" )
901 op . drop_index ( op . f ( "ix_deployment__updated" ) , table_name = "deployment" )
902 op . drop_index ( op . f ( "ix_deployment__flow_id" ) , table_name = "deployment" )
903 op . drop_table ( "deployment" )
904 op . drop_index (
905 op . f ( "ix_task_run_state_cache__updated" ) , table_name = "task_run_state_cache"
906 )
907 op . drop_index (
908 "ix_task_run_state_cache__cache_key_created_desc" ,
909 table_name = "task_run_state_cache" ,
910 )
911 op . drop_table ( "task_run_state_cache" )
912 op . drop_index ( op . f ( "ix_saved_search__updated" ) , table_name = "saved_search" )
913 op . drop_table ( "saved_search" )
914 op . drop_index ( op . f ( "ix_concurrency_limit__updated" ) , table_name = "concurrency_limit" )
915 op . drop_index ( op . f ( "ix_concurrency_limit__tag" ) , table_name = "concurrency_limit" )
916 op . drop_table ( "concurrency_limit" )
917 op . drop_index ( op . f ( "ix_log__updated" ) , table_name = "log" )
918 op . drop_index ( op . f ( "ix_log__timestamp" ) , table_name = "log" )
919 op . drop_index ( op . f ( "ix_log__task_run_id" ) , table_name = "log" )
920 op . drop_index ( op . f ( "ix_log__level" ) , table_name = "log" )
921 op . drop_index ( op . f ( "ix_log__flow_run_id" ) , table_name = "log" )
922 op . drop_table ( "log" )
923 op . drop_index ( op . f ( "ix_flow__updated" ) , table_name = "flow" )
924 op . drop_table ( "flow" )