1 """Adding scope to followers
2
3 Revision ID: 354f1ede7e9f
4 Revises: 2ac65f1758c2
5 Create Date: 2024-07-15 14:53:50.718831
6
7 """
8
9 import sqlalchemy as sa 1 ctx 1a
10 from alembic import op 1 ctx 1a
11
12 # revision identifiers, used by Alembic.
13 revision = "354f1ede7e9f" 1 ctx 1a
14 down_revision = "2ac65f1758c2" 1 ctx 1a
15 branch_labels = None 1 ctx 1a
16 depends_on = None 1 ctx 1a
17
18
19 def upgrade ( ) : 1 ctx 1a
20 with op . batch_alter_table ( "automation_event_follower" , schema = None ) as batch_op : 1 ctx 1a
21 batch_op . add_column ( sa . Column ( "scope" , sa . String ( ) , nullable = False ) ) 1 ctx 1a
22 batch_op . drop_constraint ( 1 ctx 1a
23 "uq_automation_event_follower__follower_event_id" , type_ = "unique"
24 )
25 batch_op . create_index ( 1 ctx 1a
26 batch_op . f ( "ix_automation_event_follower__scope" ) , [ "scope" ] , unique = False
27 )
28 batch_op . create_index ( 1 ctx 1a
29 "uq_follower_for_scope" , [ "scope" , "follower_event_id" ] , unique = True
30 )
31
32
33 def downgrade ( ) : 1 ctx 1a
34 with op . batch_alter_table ( "automation_event_follower" , schema = None ) as batch_op :
35 batch_op . drop_index ( "uq_follower_for_scope" )
36 batch_op . drop_index ( batch_op . f ( "ix_automation_event_follower__scope" ) )
37 batch_op . create_unique_constraint (
38 "uq_automation_event_follower__follower_event_id" , [ "follower_event_id" ]
39 )
40 batch_op . drop_column ( "scope" )