1 """Add `trigger_id` to the unique index for `automation_bucket`
2
3 Revision ID: 2b6c2b548f95
4 Revises: cc510aec4689
5 Create Date: 2024-04-09 13:18:32.041914
6
7 """
8
9 import sqlalchemy as sa 1 ctx 1a
10 from alembic import op 1 ctx 1a
11
12 import prefect . server . utilities . database 1 ctx 1a
13
14 # revision identifiers, used by Alembic.
15 revision = "2b6c2b548f95" 1 ctx 1a
16 down_revision = "cc510aec4689" 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 with op . batch_alter_table ( "automation_bucket" , schema = None ) as batch_op : 1 ctx 1a
23 batch_op . alter_column ( 1 ctx 1a
24 "trigger_id" ,
25 existing_type = prefect . server . utilities . database . UUID ( ) ,
26 nullable = False ,
27 )
28 batch_op . alter_column ( 1 ctx 1a
29 "triggered_at" ,
30 existing_type = sa . TIMESTAMP ( ) ,
31 type_ = prefect . server . utilities . database . Timestamp ( timezone = True ) ,
32 nullable = True ,
33 )
34 batch_op . drop_index ( "uq_automation_bucket__automation_id__bucketing_key" ) 1 ctx 1a
35 batch_op . create_index ( 1 ctx 1a
36 "uq_automation_bucket__automation_id__trigger_id__bucketing_key" ,
37 [ "automation_id" , "trigger_id" , "bucketing_key" ] ,
38 unique = True ,
39 )
40
41
42 def downgrade ( ) : 1 ctx 1a
43 with op . batch_alter_table ( "automation_bucket" , schema = None ) as batch_op :
44 batch_op . drop_index (
45 "uq_automation_bucket__automation_id__trigger_id__bucketing_key"
46 )
47 batch_op . create_index (
48 "uq_automation_bucket__automation_id__bucketing_key" ,
49 [ "automation_id" , "bucketing_key" ] ,
50 unique = 1 ,
51 )
52 batch_op . alter_column (
53 "trigger_id" ,
54 existing_type = prefect . server . utilities . database . UUID ( ) ,
55 nullable = True ,
56 )
57 batch_op . alter_column (
58 "triggered_at" ,
59 existing_type = prefect . server . utilities . database . Timestamp ( timezone = True ) ,
60 type_ = sa . TIMESTAMP ( ) ,
61 nullable = False ,
62 )