1 """Add slug column to deployment_schedule
2
3 Revision ID: 07ecde74d74d
4 Revises: 67f886da208e
5 Create Date: 2025-02-05 15:24:31.503016
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 = "07ecde74d74d" 1 ctx 1a
14 down_revision = "67f886da208e" 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 op . execute ( "PRAGMA foreign_keys=OFF" ) 1 ctx 1a
21
22 with op . batch_alter_table ( "deployment_schedule" , schema = None ) as batch_op : 1 ctx 1a
23 batch_op . add_column ( 1 ctx 1a
24 sa . Column ( "slug" , sa . String , nullable = True ) ,
25 )
26 batch_op . create_index ( 1 ctx 1a
27 "ix_deployment_schedule__slug" ,
28 [ "slug" ] ,
29 unique = False ,
30 if_not_exists = True ,
31 )
32
33 op . execute ( 1 ctx 1a
34 """
35 CREATE UNIQUE INDEX IF NOT EXISTS
36 ix_deployment_schedule__deployment_id__slug
37 ON deployment_schedule(deployment_id, slug)
38 WHERE slug IS NOT NULL;
39 """
40 )
41
42 op . execute ( "PRAGMA foreign_keys=ON" ) 1 ctx 1a
43
44
45 def downgrade ( ) : 1 ctx 1a
46 op . execute ( "PRAGMA foreign_keys=OFF" )
47 with op . batch_alter_table ( "deployment_schedule" , schema = None ) as batch_op :
48 batch_op . drop_index ( batch_op . f ( "ix_deployment_schedule__deployment_id__slug" ) )
49 batch_op . drop_index ( "ix_deployment_schedule__slug" )
50 batch_op . drop_column ( "slug" )
51 op . execute ( "PRAGMA foreign_keys=ON" )