1 """Automation event follower
2
3 Revision ID: cc510aec4689
4 Revises: 8644a9595a08
5 Create Date: 2024-04-09 12:57:12.420482
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 import prefect . server . utilities . database 1 ctx 1a
14 from prefect . server . events . schemas . events import ReceivedEvent 1 ctx 1a
15
16 # revision identifiers, used by Alembic.
17 revision = "cc510aec4689" 1 ctx 1a
18 down_revision = "8644a9595a08" 1 ctx 1a
19 branch_labels = None 1 ctx 1a
20 depends_on = None 1 ctx 1a
21
22
23 def upgrade ( ) : 1 ctx 1a
24 op . create_table ( 1 ctx 1a
25 "automation_event_follower" ,
26 sa . Column (
27 "leader_event_id" , prefect . server . utilities . database . UUID ( ) , nullable = False
28 ) ,
29 sa . Column (
30 "follower_event_id" ,
31 prefect . server . utilities . database . UUID ( ) ,
32 nullable = False ,
33 ) ,
34 sa . Column (
35 "received" ,
36 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
37 nullable = False ,
38 ) ,
39 sa . Column (
40 "follower" ,
41 prefect . server . utilities . database . Pydantic ( ReceivedEvent ) ,
42 nullable = False ,
43 ) ,
44 sa . Column (
45 "id" ,
46 prefect . server . utilities . database . UUID ( ) ,
47 server_default = sa . text (
48 "(\n (\n lower(hex(randomblob(4)))\n || '-'\n || lower(hex(randomblob(2)))\n || '-4'\n || substr(lower(hex(randomblob(2))),2)\n || '-'\n || substr('89ab',abs(random()) % 4 + 1, 1)\n || substr(lower(hex(randomblob(2))),2)\n || '-'\n || lower(hex(randomblob(6)))\n )\n )"
49 ) ,
50 nullable = False ,
51 ) ,
52 sa . Column (
53 "created" ,
54 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
55 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
56 nullable = False ,
57 ) ,
58 sa . Column (
59 "updated" ,
60 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
61 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
62 nullable = False ,
63 ) ,
64 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_automation_event_follower" ) ) ,
65 sa . UniqueConstraint (
66 "follower_event_id" ,
67 name = op . f ( "uq_automation_event_follower__follower_event_id" ) ,
68 ) ,
69 )
70 with op . batch_alter_table ( "automation_event_follower" , schema = None ) as batch_op : 1 ctx 1a
71 batch_op . create_index ( 1 ctx 1a
72 batch_op . f ( "ix_automation_event_follower__leader_event_id" ) ,
73 [ "leader_event_id" ] ,
74 unique = False ,
75 )
76 batch_op . create_index ( 1 ctx 1a
77 batch_op . f ( "ix_automation_event_follower__received" ) ,
78 [ "received" ] ,
79 unique = False ,
80 )
81 batch_op . create_index ( 1 ctx 1a
82 batch_op . f ( "ix_automation_event_follower__updated" ) ,
83 [ "updated" ] ,
84 unique = False ,
85 )
86
87
88 def downgrade ( ) : 1 ctx 1a
89 with op . batch_alter_table ( "automation_event_follower" , schema = None ) as batch_op :
90 batch_op . drop_index ( batch_op . f ( "ix_automation_event_follower__updated" ) )
91 batch_op . drop_index ( batch_op . f ( "ix_automation_event_follower__received" ) )
92 batch_op . drop_index ( batch_op . f ( "ix_automation_event_follower__leader_event_id" ) )
93
94 op . drop_table ( "automation_event_follower" )