1 """Add indices for coalesced `start time` sorts
2
3 Revision ID: 4f90ad6349bd
4 Revises: a0284438370e
5 Create Date: 2022-11-10 16:59:21.884051
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 = "4f90ad6349bd" 1 ctx 1a
14 down_revision = "a0284438370e" 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 # ### commands auto generated by Alembic - please adjust! ###
21 with op . batch_alter_table ( "flow_run" , schema = None ) as batch_op : 1 ctx 1a
22 batch_op . drop_index ( 1 ctx 1a
23 "ix_flow_run__scheduler_deployment_id_auto_scheduled_next_scheduled_start_time"
24 )
25 batch_op . create_index ( 1 ctx 1a
26 "ix_flow_run__coalesce_start_time_expected_start_time_asc" ,
27 [ sa . text ( "coalesce('start_time', 'expected_start_time') ASC" ) ] ,
28 unique = False ,
29 )
30 batch_op . create_index ( 1 ctx 1a
31 "ix_flow_run__coalesce_start_time_expected_start_time_desc" ,
32 [ sa . text ( "coalesce('start_time', 'expected_start_time') DESC" ) ] ,
33 unique = False ,
34 )
35
36 # ### end Alembic commands ###
37
38
39 def downgrade ( ) : 1 ctx 1a
40 # ### commands auto generated by Alembic - please adjust! ###
41 with op . batch_alter_table ( "flow_run" , schema = None ) as batch_op :
42 batch_op . execute (
43 "DROP INDEX IF EXISTS"
44 " ix_flow_run__coalesce_start_time_expected_start_time_desc"
45 )
46 batch_op . execute (
47 "DROP INDEX IF EXISTS"
48 " ix_flow_run__coalesce_start_time_expected_start_time_asc"
49 )
50 batch_op . create_index (
51 "ix_flow_run__scheduler_deployment_id_auto_scheduled_next_scheduled_start_time" ,
52 [ "deployment_id" , "auto_scheduled" , "next_scheduled_start_time" ] ,
53 unique = False ,
54 )
55 # ### end Alembic commands ###