@@ -16,29 +16,41 @@ against an empty schema):
1616
1717``` python
1818# ### commands auto generated by Alembic - please adjust! ###
19- op.create_table(' outbox' ,
20- sa.Column(' id' , sa.BigInteger(), autoincrement = True , nullable = False ),
21- sa.Column(' queue' , sa.String(length = 255 ), nullable = False ),
22- sa.Column(' payload' , sa.LargeBinary(), nullable = False ),
23- sa.Column(' headers' , postgresql.JSONB(astext_type = sa.Text()), nullable = True ),
24- sa.Column(' attempts_count' , sa.BigInteger(), server_default = ' 0' , nullable = False ),
25- sa.Column(' deliveries_count' , sa.BigInteger(), server_default = ' 0' , nullable = False ),
26- sa.Column(' created_at' , sa.DateTime(timezone = True ), server_default = sa.text(' now()' ), nullable = False ),
27- sa.Column(' next_attempt_at' , sa.DateTime(timezone = True ), server_default = sa.text(' now()' ), nullable = False ),
28- sa.Column(' first_attempt_at' , sa.DateTime(timezone = True ), nullable = True ),
29- sa.Column(' last_attempt_at' , sa.DateTime(timezone = True ), nullable = True ),
30- sa.Column(' acquired_at' , sa.DateTime(timezone = True ), nullable = True ),
31- sa.Column(' acquired_token' , sa.Uuid(), nullable = True ),
32- sa.Column(' timer_id' , sa.String(length = 255 ), nullable = True ),
33- sa.CheckConstraint(' (acquired_token IS NULL) = (acquired_at IS NULL)' , name = ' outbox_lease_ck' ),
34- sa.PrimaryKeyConstraint(' id' )
19+ op.create_table(
20+ " outbox" ,
21+ sa.Column(" id" , sa.BigInteger(), autoincrement = True , nullable = False ),
22+ sa.Column(" queue" , sa.String(length = 255 ), nullable = False ),
23+ sa.Column(" payload" , sa.LargeBinary(), nullable = False ),
24+ sa.Column(" headers" , postgresql.JSONB(astext_type = sa.Text()), nullable = True ),
25+ sa.Column(" attempts_count" , sa.BigInteger(), server_default = " 0" , nullable = False ),
26+ sa.Column(" deliveries_count" , sa.BigInteger(), server_default = " 0" , nullable = False ),
27+ sa.Column(" created_at" , sa.DateTime(timezone = True ), server_default = sa.text(" now()" ), nullable = False ),
28+ sa.Column(" next_attempt_at" , sa.DateTime(timezone = True ), server_default = sa.text(" now()" ), nullable = False ),
29+ sa.Column(" first_attempt_at" , sa.DateTime(timezone = True ), nullable = True ),
30+ sa.Column(" last_attempt_at" , sa.DateTime(timezone = True ), nullable = True ),
31+ sa.Column(" acquired_at" , sa.DateTime(timezone = True ), nullable = True ),
32+ sa.Column(" acquired_token" , sa.Uuid(), nullable = True ),
33+ sa.Column(" timer_id" , sa.String(length = 255 ), nullable = True ),
34+ sa.CheckConstraint(" (acquired_token IS NULL) = (acquired_at IS NULL)" , name = " outbox_lease_ck" ),
35+ sa.PrimaryKeyConstraint(" id" ),
36+ )
37+ op.create_index(
38+ " outbox_lease_idx" ,
39+ " outbox" ,
40+ [" queue" , " acquired_at" ],
41+ unique = False ,
42+ postgresql_where = sa.text(" acquired_token IS NOT NULL" ),
43+ )
44+ op.create_index(
45+ " outbox_pending_idx" ,
46+ " outbox" ,
47+ [" queue" , " next_attempt_at" ],
48+ unique = False ,
49+ postgresql_where = sa.text(" acquired_token IS NULL" ),
50+ )
51+ op.create_index(
52+ " outbox_timer_id_uq" , " outbox" , [" queue" , " timer_id" ], unique = True , postgresql_where = sa.text(" timer_id IS NOT NULL" )
3553)
36- op.create_index(' outbox_lease_idx' , ' outbox' , [' queue' , ' acquired_at' ], unique = False ,
37- postgresql_where = sa.text(' acquired_token IS NOT NULL' ))
38- op.create_index(' outbox_pending_idx' , ' outbox' , [' queue' , ' next_attempt_at' ], unique = False ,
39- postgresql_where = sa.text(' acquired_token IS NULL' ))
40- op.create_index(' outbox_timer_id_uq' , ' outbox' , [' queue' , ' timer_id' ], unique = True ,
41- postgresql_where = sa.text(' timer_id IS NOT NULL' ))
4254# ### end Alembic commands ###
4355```
4456
@@ -89,21 +101,22 @@ The captured `upgrade()` body:
89101
90102``` python
91103# ### commands auto generated by Alembic - please adjust! ###
92- op.create_table(' outbox_dlq' ,
93- sa.Column(' id' , sa.BigInteger(), autoincrement = True , nullable = False ),
94- sa.Column(' original_id' , sa.BigInteger(), nullable = False ),
95- sa.Column(' queue' , sa.String(length = 255 ), nullable = False ),
96- sa.Column(' payload' , sa.LargeBinary(), nullable = False ),
97- sa.Column(' headers' , postgresql.JSONB(astext_type = sa.Text()), nullable = True ),
98- sa.Column(' deliveries_count' , sa.BigInteger(), nullable = False ),
99- sa.Column(' created_at' , sa.DateTime(timezone = True ), nullable = False ),
100- sa.Column(' failed_at' , sa.DateTime(timezone = True ), server_default = sa.text(' now()' ), nullable = False ),
101- sa.Column(' failure_reason' , sa.String(length = 64 ), nullable = False ),
102- sa.Column(' last_exception' , sa.String(), nullable = True ),
103- sa.Column(' timer_id' , sa.String(length = 255 ), nullable = True ),
104- sa.PrimaryKeyConstraint(' id' )
104+ op.create_table(
105+ " outbox_dlq" ,
106+ sa.Column(" id" , sa.BigInteger(), autoincrement = True , nullable = False ),
107+ sa.Column(" original_id" , sa.BigInteger(), nullable = False ),
108+ sa.Column(" queue" , sa.String(length = 255 ), nullable = False ),
109+ sa.Column(" payload" , sa.LargeBinary(), nullable = False ),
110+ sa.Column(" headers" , postgresql.JSONB(astext_type = sa.Text()), nullable = True ),
111+ sa.Column(" deliveries_count" , sa.BigInteger(), nullable = False ),
112+ sa.Column(" created_at" , sa.DateTime(timezone = True ), nullable = False ),
113+ sa.Column(" failed_at" , sa.DateTime(timezone = True ), server_default = sa.text(" now()" ), nullable = False ),
114+ sa.Column(" failure_reason" , sa.String(length = 64 ), nullable = False ),
115+ sa.Column(" last_exception" , sa.String(), nullable = True ),
116+ sa.Column(" timer_id" , sa.String(length = 255 ), nullable = True ),
117+ sa.PrimaryKeyConstraint(" id" ),
105118)
106- op.create_index(' outbox_dlq_queue_failed_idx' , ' outbox_dlq' , [' queue' , ' failed_at' ], unique = False )
119+ op.create_index(" outbox_dlq_queue_failed_idx" , " outbox_dlq" , [" queue" , " failed_at" ], unique = False )
107120# ### end Alembic commands ###
108121```
109122
@@ -268,11 +281,11 @@ pointer to this section. Re-running autogenerate produces an empty
268281``` python
269282# Drop first ONLY if the constraint exists with a wrong predicate; skip the
270283# drop if it is absent entirely.
271- op.drop_constraint(' outbox_lease_ck' , ' outbox' , type_ = ' check' )
284+ op.drop_constraint(" outbox_lease_ck" , " outbox" , type_ = " check" )
272285op.create_check_constraint(
273- ' outbox_lease_ck' ,
274- ' outbox' ,
275- ' (acquired_token IS NULL) = (acquired_at IS NULL)' ,
286+ " outbox_lease_ck" ,
287+ " outbox" ,
288+ " (acquired_token IS NULL) = (acquired_at IS NULL)" ,
276289)
277290```
278291
@@ -288,13 +301,13 @@ three indexes and their expected shape:
288301| ` outbox_timer_id_uq ` | ` queue, timer_id ` | yes | ` timer_id IS NOT NULL ` |
289302
290303``` python
291- op.drop_index(' outbox_timer_id_uq' , table_name = ' outbox' )
304+ op.drop_index(" outbox_timer_id_uq" , table_name = " outbox" )
292305op.create_index(
293- ' outbox_timer_id_uq' ,
294- ' outbox' ,
295- [' queue' , ' timer_id' ],
306+ " outbox_timer_id_uq" ,
307+ " outbox" ,
308+ [" queue" , " timer_id" ],
296309 unique = True ,
297- postgresql_where = sa.text(' timer_id IS NOT NULL' ),
310+ postgresql_where = sa.text(" timer_id IS NOT NULL" ),
298311)
299312```
300313
@@ -339,7 +352,7 @@ faster, no vacuum debt.
339352# ### Convert outbox_dlq to range-partitioned by failed_at ###
340353
341354# Rename the existing table out of the way.
342- op.rename_table(' outbox_dlq' , ' outbox_dlq_old' )
355+ op.rename_table(" outbox_dlq" , " outbox_dlq_old" )
343356
344357# Create the partitioned parent. The PRIMARY KEY must include the
345358# partition key, so we extend it to (id, failed_at).
@@ -381,7 +394,7 @@ op.execute("""
381394 WHERE failed_at >= '2026-05-01';
382395""" )
383396
384- op.drop_table(' outbox_dlq_old' )
397+ op.drop_table(" outbox_dlq_old" )
385398```
386399
387400` validate_schema() ` continues to work against the partitioned table —
0 commit comments