The best way to control Claude Code, Codex and more from any computer or phone
fix(relay): stop delivery attempts from growing the database forever (#26141)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 27, 2026 at 19:11 UTC
c3b40b97f751083fc9ade4346b72d4250a4e60d0
8 files changed
+1710
-9
infra/relay/migrations/postgres/20261027210820_delivery_attempts_retention/migration.sql
new
+6
@@ -0,0 +1,6 @@
1
+-- Alchemy runs migrations in a transaction, so CONCURRENTLY is unavailable here. Build
2
+-- idx_relay_delivery_attempts_created concurrently before deploying so this is a no-op.
3
+DROP INDEX IF EXISTS "idx_relay_delivery_attempts_environment";--> statement-breakpoint
4
+DROP INDEX IF EXISTS "idx_relay_agent_activity_rows_updated";--> statement-breakpoint
5
+DROP INDEX IF EXISTS "idx_relay_environment_credentials_environment";--> statement-breakpoint
6
+CREATE INDEX IF NOT EXISTS "idx_relay_delivery_attempts_created" ON "relay_delivery_attempts" ("created_at");
infra/relay/migrations/postgres/20261027210820_delivery_attempts_retention/snapshot.json
new
+1571
@@ -0,0 +1,1571 @@
1
+{
2
+ "version": "8",
3
+ "dialect": "postgres",
4
+ "id": "7d8c1702-6f47-4453-a8ee-66ce5e3bfb41",
5
+ "prevIds": ["f8594baa-6f4a-4a0d-a7f0-0aa717dfe785"],
6
+ "ddl": [
7
+ {
8
+ "isRlsEnabled": false,
9
+ "name": "relay_agent_activity_rows",
10
+ "entityType": "tables",
11
+ "schema": "public"
12
+ },
13
+ {
14
+ "isRlsEnabled": false,
15
+ "name": "relay_delivery_attempts",
16
+ "entityType": "tables",
17
+ "schema": "public"
18
+ },
19
+ {
20
+ "isRlsEnabled": false,
21
+ "name": "relay_dpop_proofs",
22
+ "entityType": "tables",
23
+ "schema": "public"
24
+ },
25
+ {
26
+ "isRlsEnabled": false,
27
+ "name": "relay_environment_credentials",
28
+ "entityType": "tables",
29
+ "schema": "public"
30
+ },
31
+ {
32
+ "isRlsEnabled": false,
33
+ "name": "relay_environment_links",
34
+ "entityType": "tables",
35
+ "schema": "public"
36
+ },
37
+ {
38
+ "isRlsEnabled": false,
39
+ "name": "relay_live_activities",
40
+ "entityType": "tables",
41
+ "schema": "public"
42
+ },
43
+ {
44
+ "isRlsEnabled": false,
45
+ "name": "relay_managed_endpoint_allocations",
46
+ "entityType": "tables",
47
+ "schema": "public"
48
+ },
49
+ {
50
+ "isRlsEnabled": false,
51
+ "name": "relay_managed_tunnel_limits",
52
+ "entityType": "tables",
53
+ "schema": "public"
54
+ },
55
+ {
56
+ "isRlsEnabled": false,
57
+ "name": "relay_mobile_devices",
58
+ "entityType": "tables",
59
+ "schema": "public"
60
+ },
61
+ {
62
+ "isRlsEnabled": false,
63
+ "name": "relay_upstream_api_pauses",
64
+ "entityType": "tables",
65
+ "schema": "public"
66
+ },
67
+ {
68
+ "type": "varchar(191)",
69
+ "typeSchema": null,
70
+ "notNull": true,
71
+ "dimensions": 0,
72
+ "default": null,
73
+ "generated": null,
74
+ "identity": null,
75
+ "name": "environment_id",
76
+ "entityType": "columns",
77
+ "schema": "public",
78
+ "table": "relay_agent_activity_rows"
79
+ },
80
+ {
81
+ "type": "text",
82
+ "typeSchema": null,
83
+ "notNull": true,
84
+ "dimensions": 0,
85
+ "default": null,
86
+ "generated": null,
87
+ "identity": null,
88
+ "name": "environment_public_key",
89
+ "entityType": "columns",
90
+ "schema": "public",
91
+ "table": "relay_agent_activity_rows"
92
+ },
93
+ {
94
+ "type": "varchar(512)",
95
+ "typeSchema": null,
96
+ "notNull": true,
97
+ "dimensions": 0,
98
+ "default": null,
99
+ "generated": null,
100
+ "identity": null,
101
+ "name": "thread_id",
102
+ "entityType": "columns",
103
+ "schema": "public",
104
+ "table": "relay_agent_activity_rows"
105
+ },
106
+ {
107
+ "type": "jsonb",
108
+ "typeSchema": null,
109
+ "notNull": true,
110
+ "dimensions": 0,
111
+ "default": null,
112
+ "generated": null,
113
+ "identity": null,
114
+ "name": "state_json",
115
+ "entityType": "columns",
116
+ "schema": "public",
117
+ "table": "relay_agent_activity_rows"
118
+ },
119
+ {
120
+ "type": "varchar(64)",
121
+ "typeSchema": null,
122
+ "notNull": true,
123
+ "dimensions": 0,
124
+ "default": null,
125
+ "generated": null,
126
+ "identity": null,
127
+ "name": "updated_at",
128
+ "entityType": "columns",
129
+ "schema": "public",
130
+ "table": "relay_agent_activity_rows"
131
+ },
132
+ {
133
+ "type": "varchar(64)",
134
+ "typeSchema": null,
135
+ "notNull": true,
136
+ "dimensions": 0,
137
+ "default": null,
138
+ "generated": null,
139
+ "identity": null,
140
+ "name": "created_at",
141
+ "entityType": "columns",
142
+ "schema": "public",
143
+ "table": "relay_agent_activity_rows"
144
+ },
145
+ {
146
+ "type": "varchar(36)",
147
+ "typeSchema": null,
148
+ "notNull": true,
149
+ "dimensions": 0,
150
+ "default": null,
151
+ "generated": null,
152
+ "identity": null,
153
+ "name": "id",
154
+ "entityType": "columns",
155
+ "schema": "public",
156
+ "table": "relay_delivery_attempts"
157
+ },
158
+ {
159
+ "type": "varchar(64)",
160
+ "typeSchema": null,
161
+ "notNull": true,
162
+ "dimensions": 0,
163
+ "default": null,
164
+ "generated": null,
165
+ "identity": null,
166
+ "name": "created_at",
167
+ "entityType": "columns",
168
+ "schema": "public",
169
+ "table": "relay_delivery_attempts"
170
+ },
171
+ {
172
+ "type": "varchar(255)",
173
+ "typeSchema": null,
174
+ "notNull": false,
175
+ "dimensions": 0,
176
+ "default": null,
177
+ "generated": null,
178
+ "identity": null,
179
+ "name": "user_id",
180
+ "entityType": "columns",
181
+ "schema": "public",
182
+ "table": "relay_delivery_attempts"
183
+ },
184
+ {
185
+ "type": "varchar(191)",
186
+ "typeSchema": null,
187
+ "notNull": false,
188
+ "dimensions": 0,
189
+ "default": null,
190
+ "generated": null,
191
+ "identity": null,
192
+ "name": "environment_id",
193
+ "entityType": "columns",
194
+ "schema": "public",
195
+ "table": "relay_delivery_attempts"
196
+ },
197
+ {
198
+ "type": "varchar(512)",
199
+ "typeSchema": null,
200
+ "notNull": false,
201
+ "dimensions": 0,
202
+ "default": null,
203
+ "generated": null,
204
+ "identity": null,
205
+ "name": "thread_id",
206
+ "entityType": "columns",
207
+ "schema": "public",
208
+ "table": "relay_delivery_attempts"
209
+ },
210
+ {
211
+ "type": "varchar(255)",
212
+ "typeSchema": null,
213
+ "notNull": false,
214
+ "dimensions": 0,
215
+ "default": null,
216
+ "generated": null,
217
+ "identity": null,
218
+ "name": "device_id",
219
+ "entityType": "columns",
220
+ "schema": "public",
221
+ "table": "relay_delivery_attempts"
222
+ },
223
+ {
224
+ "type": "varchar(64)",
225
+ "typeSchema": null,
226
+ "notNull": true,
227
+ "dimensions": 0,
228
+ "default": null,
229
+ "generated": null,
230
+ "identity": null,
231
+ "name": "kind",
232
+ "entityType": "columns",
233
+ "schema": "public",
234
+ "table": "relay_delivery_attempts"
235
+ },
236
+ {
237
+ "type": "varchar(64)",
238
+ "typeSchema": null,
239
+ "notNull": false,
240
+ "dimensions": 0,
241
+ "default": null,
242
+ "generated": null,
243
+ "identity": null,
244
+ "name": "source_job_id",
245
+ "entityType": "columns",
246
+ "schema": "public",
247
+ "table": "relay_delivery_attempts"
248
+ },
249
+ {
250
+ "type": "varchar(16)",
251
+ "typeSchema": null,
252
+ "notNull": false,
253
+ "dimensions": 0,
254
+ "default": null,
255
+ "generated": null,
256
+ "identity": null,
257
+ "name": "token_suffix",
258
+ "entityType": "columns",
259
+ "schema": "public",
260
+ "table": "relay_delivery_attempts"
261
+ },
262
+ {
263
+ "type": "integer",
264
+ "typeSchema": null,
265
+ "notNull": false,
266
+ "dimensions": 0,
267
+ "default": null,
268
+ "generated": null,
269
+ "identity": null,
270
+ "name": "apns_status",
271
+ "entityType": "columns",
272
+ "schema": "public",
273
+ "table": "relay_delivery_attempts"
274
+ },
275
+ {
276
+ "type": "text",
277
+ "typeSchema": null,
278
+ "notNull": false,
279
+ "dimensions": 0,
280
+ "default": null,
281
+ "generated": null,
282
+ "identity": null,
283
+ "name": "apns_reason",
284
+ "entityType": "columns",
285
+ "schema": "public",
286
+ "table": "relay_delivery_attempts"
287
+ },
288
+ {
289
+ "type": "varchar(128)",
290
+ "typeSchema": null,
291
+ "notNull": false,
292
+ "dimensions": 0,
293
+ "default": null,
294
+ "generated": null,
295
+ "identity": null,
296
+ "name": "apns_id",
297
+ "entityType": "columns",
298
+ "schema": "public",
299
+ "table": "relay_delivery_attempts"
300
+ },
301
+ {
302
+ "type": "text",
303
+ "typeSchema": null,
304
+ "notNull": false,
305
+ "dimensions": 0,
306
+ "default": null,
307
+ "generated": null,
308
+ "identity": null,
309
+ "name": "transport_error",
310
+ "entityType": "columns",
311
+ "schema": "public",
312
+ "table": "relay_delivery_attempts"
313
+ },
314
+ {
315
+ "type": "varchar(128)",
316
+ "typeSchema": null,
317
+ "notNull": true,
318
+ "dimensions": 0,
319
+ "default": null,
320
+ "generated": null,
321
+ "identity": null,
322
+ "name": "thumbprint",
323
+ "entityType": "columns",
324
+ "schema": "public",
325
+ "table": "relay_dpop_proofs"
326
+ },
327
+ {
328
+ "type": "varchar(255)",
329
+ "typeSchema": null,
330
+ "notNull": true,
331
+ "dimensions": 0,
332
+ "default": null,
333
+ "generated": null,
334
+ "identity": null,
335
+ "name": "jti",
336
+ "entityType": "columns",
337
+ "schema": "public",
338
+ "table": "relay_dpop_proofs"
339
+ },
340
+ {
341
+ "type": "integer",
342
+ "typeSchema": null,
343
+ "notNull": true,
344
+ "dimensions": 0,
345
+ "default": null,
346
+ "generated": null,
347
+ "identity": null,
348
+ "name": "iat",
349
+ "entityType": "columns",
350
+ "schema": "public",
351
+ "table": "relay_dpop_proofs"
352
+ },
353
+ {
354
+ "type": "varchar(64)",
355
+ "typeSchema": null,
356
+ "notNull": true,
357
+ "dimensions": 0,
358
+ "default": null,
359
+ "generated": null,
360
+ "identity": null,
361
+ "name": "expires_at",
362
+ "entityType": "columns",
363
+ "schema": "public",
364
+ "table": "relay_dpop_proofs"
365
+ },
366
+ {
367
+ "type": "varchar(64)",
368
+ "typeSchema": null,
369
+ "notNull": true,
370
+ "dimensions": 0,
371
+ "default": null,
372
+ "generated": null,
373
+ "identity": null,
374
+ "name": "created_at",
375
+ "entityType": "columns",
376
+ "schema": "public",
377
+ "table": "relay_dpop_proofs"
378
+ },
379
+ {
380
+ "type": "varchar(64)",
381
+ "typeSchema": null,
382
+ "notNull": true,
383
+ "dimensions": 0,
384
+ "default": null,
385
+ "generated": null,
386
+ "identity": null,
387
+ "name": "credential_id",
388
+ "entityType": "columns",
389
+ "schema": "public",
390
+ "table": "relay_environment_credentials"
391
+ },
392
+ {
393
+ "type": "varchar(191)",
394
+ "typeSchema": null,
395
+ "notNull": true,
396
+ "dimensions": 0,
397
+ "default": null,
398
+ "generated": null,
399
+ "identity": null,
400
+ "name": "environment_id",
401
+ "entityType": "columns",
402
+ "schema": "public",
403
+ "table": "relay_environment_credentials"
404
+ },
405
+ {
406
+ "type": "text",
407
+ "typeSchema": null,
408
+ "notNull": true,
409
+ "dimensions": 0,
410
+ "default": null,
411
+ "generated": null,
412
+ "identity": null,
413
+ "name": "environment_public_key",
414
+ "entityType": "columns",
415
+ "schema": "public",
416
+ "table": "relay_environment_credentials"
417
+ },
418
+ {
419
+ "type": "varchar(191)",
420
+ "typeSchema": null,
421
+ "notNull": true,
422
+ "dimensions": 0,
423
+ "default": null,
424
+ "generated": null,
425
+ "identity": null,
426
+ "name": "credential_hash",
427
+ "entityType": "columns",
428
+ "schema": "public",
429
+ "table": "relay_environment_credentials"
430
+ },
431
+ {
432
+ "type": "varchar(64)",
433
+ "typeSchema": null,
434
+ "notNull": false,
435
+ "dimensions": 0,
436
+ "default": null,
437
+ "generated": null,
438
+ "identity": null,
439
+ "name": "revoked_at",
440
+ "entityType": "columns",
441
+ "schema": "public",
442
+ "table": "relay_environment_credentials"
443
+ },
444
+ {
445
+ "type": "varchar(64)",
446
+ "typeSchema": null,
447
+ "notNull": true,
448
+ "dimensions": 0,
449
+ "default": null,
450
+ "generated": null,
451
+ "identity": null,
452
+ "name": "created_at",
453
+ "entityType": "columns",
454
+ "schema": "public",
455
+ "table": "relay_environment_credentials"
456
+ },
457
+ {
458
+ "type": "varchar(64)",
459
+ "typeSchema": null,
460
+ "notNull": true,
461
+ "dimensions": 0,
462
+ "default": null,
463
+ "generated": null,
464
+ "identity": null,
465
+ "name": "updated_at",
466
+ "entityType": "columns",
467
+ "schema": "public",
468
+ "table": "relay_environment_credentials"
469
+ },
470
+ {
471
+ "type": "varchar(191)",
472
+ "typeSchema": null,
473
+ "notNull": true,
474
+ "dimensions": 0,
475
+ "default": null,
476
+ "generated": null,
477
+ "identity": null,
478
+ "name": "user_id",
479
+ "entityType": "columns",
480
+ "schema": "public",
481
+ "table": "relay_environment_links"
482
+ },
483
+ {
484
+ "type": "varchar(191)",
485
+ "typeSchema": null,
486
+ "notNull": true,
487
+ "dimensions": 0,
488
+ "default": null,
489
+ "generated": null,
490
+ "identity": null,
491
+ "name": "environment_id",
492
+ "entityType": "columns",
493
+ "schema": "public",
494
+ "table": "relay_environment_links"
495
+ },
496
+ {
497
+ "type": "text",
498
+ "typeSchema": null,
499
+ "notNull": true,
500
+ "dimensions": 0,
501
+ "default": "'T3 Environment'",
502
+ "generated": null,
503
+ "identity": null,
504
+ "name": "environment_label",
505
+ "entityType": "columns",
506
+ "schema": "public",
507
+ "table": "relay_environment_links"
508
+ },
509
+ {
510
+ "type": "text",
511
+ "typeSchema": null,
512
+ "notNull": true,
513
+ "dimensions": 0,
514
+ "default": null,
515
+ "generated": null,
516
+ "identity": null,
517
+ "name": "environment_public_key",
518
+ "entityType": "columns",
519
+ "schema": "public",
520
+ "table": "relay_environment_links"
521
+ },
522
+ {
523
+ "type": "text",
524
+ "typeSchema": null,
525
+ "notNull": true,
526
+ "dimensions": 0,
527
+ "default": null,
528
+ "generated": null,
529
+ "identity": null,
530
+ "name": "endpoint_http_base_url",
531
+ "entityType": "columns",
532
+ "schema": "public",
533
+ "table": "relay_environment_links"
534
+ },
535
+ {
536
+ "type": "text",
537
+ "typeSchema": null,
538
+ "notNull": true,
539
+ "dimensions": 0,
540
+ "default": null,
541
+ "generated": null,
542
+ "identity": null,
543
+ "name": "endpoint_ws_base_url",
544
+ "entityType": "columns",
545
+ "schema": "public",
546
+ "table": "relay_environment_links"
547
+ },
548
+ {
549
+ "type": "varchar(32)",
550
+ "typeSchema": null,
551
+ "notNull": true,
552
+ "dimensions": 0,
553
+ "default": null,
554
+ "generated": null,
555
+ "identity": null,
556
+ "name": "endpoint_provider_kind",
557
+ "entityType": "columns",
558
+ "schema": "public",
559
+ "table": "relay_environment_links"
560
+ },
561
+ {
562
+ "type": "boolean",
563
+ "typeSchema": null,
564
+ "notNull": true,
565
+ "dimensions": 0,
566
+ "default": "true",
567
+ "generated": null,
568
+ "identity": null,
569
+ "name": "notifications_enabled",
570
+ "entityType": "columns",
571
+ "schema": "public",
572
+ "table": "relay_environment_links"
573
+ },
574
+ {
575
+ "type": "boolean",
576
+ "typeSchema": null,
577
+ "notNull": true,
578
+ "dimensions": 0,
579
+ "default": "true",
580
+ "generated": null,
581
+ "identity": null,
582
+ "name": "live_activities_enabled",
583
+ "entityType": "columns",
584
+ "schema": "public",
585
+ "table": "relay_environment_links"
586
+ },
587
+ {
588
+ "type": "boolean",
589
+ "typeSchema": null,
590
+ "notNull": true,
591
+ "dimensions": 0,
592
+ "default": "false",
593
+ "generated": null,
594
+ "identity": null,
595
+ "name": "managed_tunnels_enabled",
596
+ "entityType": "columns",
597
+ "schema": "public",
598
+ "table": "relay_environment_links"
599
+ },
600
+ {
601
+ "type": "boolean",
602
+ "typeSchema": null,
603
+ "notNull": true,
604
+ "dimensions": 0,
605
+ "default": "false",
606
+ "generated": null,
607
+ "identity": null,
608
+ "name": "hold_webhooks_while_offline",
609
+ "entityType": "columns",
610
+ "schema": "public",
611
+ "table": "relay_environment_links"
612
+ },
613
+ {
614
+ "type": "varchar(191)",
615
+ "typeSchema": null,
616
+ "notNull": false,
617
+ "dimensions": 0,
618
+ "default": null,
619
+ "generated": null,
620
+ "identity": null,
621
+ "name": "created_by_device_id",
622
+ "entityType": "columns",
623
+ "schema": "public",
624
+ "table": "relay_environment_links"
625
+ },
626
+ {
627
+ "type": "varchar(64)",
628
+ "typeSchema": null,
629
+ "notNull": false,
630
+ "dimensions": 0,
631
+ "default": null,
632
+ "generated": null,
633
+ "identity": null,
634
+ "name": "revoked_at",
635
+ "entityType": "columns",
636
+ "schema": "public",
637
+ "table": "relay_environment_links"
638
+ },
639
+ {
640
+ "type": "varchar(64)",
641
+ "typeSchema": null,
642
+ "notNull": true,
643
+ "dimensions": 0,
644
+ "default": null,
645
+ "generated": null,
646
+ "identity": null,
647
+ "name": "created_at",
648
+ "entityType": "columns",
649
+ "schema": "public",
650
+ "table": "relay_environment_links"
651
+ },
652
+ {
653
+ "type": "varchar(64)",
654
+ "typeSchema": null,
655
+ "notNull": true,
656
+ "dimensions": 0,
657
+ "default": null,
658
+ "generated": null,
659
+ "identity": null,
660
+ "name": "updated_at",
661
+ "entityType": "columns",
662
+ "schema": "public",
663
+ "table": "relay_environment_links"
664
+ },
665
+ {
666
+ "type": "varchar(255)",
667
+ "typeSchema": null,
668
+ "notNull": true,
669
+ "dimensions": 0,
670
+ "default": null,
671
+ "generated": null,
672
+ "identity": null,
673
+ "name": "user_id",
674
+ "entityType": "columns",
675
+ "schema": "public",
676
+ "table": "relay_live_activities"
677
+ },
678
+ {
679
+ "type": "varchar(255)",
680
+ "typeSchema": null,
681
+ "notNull": true,
682
+ "dimensions": 0,
683
+ "default": null,
684
+ "generated": null,
685
+ "identity": null,
686
+ "name": "device_id",
687
+ "entityType": "columns",
688
+ "schema": "public",
689
+ "table": "relay_live_activities"
690
+ },
691
+ {
692
+ "type": "text",
693
+ "typeSchema": null,
694
+ "notNull": false,
695
+ "dimensions": 0,
696
+ "default": null,
697
+ "generated": null,
698
+ "identity": null,
699
+ "name": "activity_push_token",
700
+ "entityType": "columns",
701
+ "schema": "public",
702
+ "table": "relay_live_activities"
703
+ },
704
+ {
705
+ "type": "varchar(64)",
706
+ "typeSchema": null,
707
+ "notNull": false,
708
+ "dimensions": 0,
709
+ "default": null,
710
+ "generated": null,
711
+ "identity": null,
712
+ "name": "remote_start_queued_at",
713
+ "entityType": "columns",
714
+ "schema": "public",
715
+ "table": "relay_live_activities"
716
+ },
717
+ {
718
+ "type": "varchar(64)",
719
+ "typeSchema": null,
720
+ "notNull": false,
721
+ "dimensions": 0,
722
+ "default": null,
723
+ "generated": null,
724
+ "identity": null,
725
+ "name": "remote_started_at",
726
+ "entityType": "columns",
727
+ "schema": "public",
728
+ "table": "relay_live_activities"
729
+ },
730
+ {
731
+ "type": "varchar(64)",
732
+ "typeSchema": null,
733
+ "notNull": false,
734
+ "dimensions": 0,
735
+ "default": null,
736
+ "generated": null,
737
+ "identity": null,
738
+ "name": "ended_at",
739
+ "entityType": "columns",
740
+ "schema": "public",
741
+ "table": "relay_live_activities"
742
+ },
743
+ {
744
+ "type": "jsonb",
745
+ "typeSchema": null,
746
+ "notNull": false,
747
+ "dimensions": 0,
748
+ "default": null,
749
+ "generated": null,
750
+ "identity": null,
751
+ "name": "last_aggregate_json",
752
+ "entityType": "columns",
753
+ "schema": "public",
754
+ "table": "relay_live_activities"
755
+ },
756
+ {
757
+ "type": "varchar(64)",
758
+ "typeSchema": null,
759
+ "notNull": false,
760
+ "dimensions": 0,
761
+ "default": null,
762
+ "generated": null,
763
+ "identity": null,
764
+ "name": "last_live_activity_delivery_at",
765
+ "entityType": "columns",
766
+ "schema": "public",
767
+ "table": "relay_live_activities"
768
+ },
769
+ {
770
+ "type": "varchar(64)",
771
+ "typeSchema": null,
772
+ "notNull": true,
773
+ "dimensions": 0,
774
+ "default": null,
775
+ "generated": null,
776
+ "identity": null,
777
+ "name": "created_at",
778
+ "entityType": "columns",
779
+ "schema": "public",
780
+ "table": "relay_live_activities"
781
+ },
782
+ {
783
+ "type": "varchar(64)",
784
+ "typeSchema": null,
785
+ "notNull": true,
786
+ "dimensions": 0,
787
+ "default": null,
788
+ "generated": null,
789
+ "identity": null,
790
+ "name": "updated_at",
791
+ "entityType": "columns",
792
+ "schema": "public",
793
+ "table": "relay_live_activities"
794
+ },
795
+ {
796
+ "type": "varchar(191)",
797
+ "typeSchema": null,
798
+ "notNull": true,
799
+ "dimensions": 0,
800
+ "default": null,
801
+ "generated": null,
802
+ "identity": null,
803
+ "name": "user_id",
804
+ "entityType": "columns",
805
+ "schema": "public",
806
+ "table": "relay_managed_endpoint_allocations"
807
+ },
808
+ {
809
+ "type": "varchar(191)",
810
+ "typeSchema": null,
811
+ "notNull": true,
812
+ "dimensions": 0,
813
+ "default": null,
814
+ "generated": null,
815
+ "identity": null,
816
+ "name": "environment_id",
817
+ "entityType": "columns",
818
+ "schema": "public",
819
+ "table": "relay_managed_endpoint_allocations"
820
+ },
821
+ {
822
+ "type": "text",
823
+ "typeSchema": null,
824
+ "notNull": true,
825
+ "dimensions": 0,
826
+ "default": null,
827
+ "generated": null,
828
+ "identity": null,
829
+ "name": "hostname",
830
+ "entityType": "columns",
831
+ "schema": "public",
832
+ "table": "relay_managed_endpoint_allocations"
833
+ },
834
+ {
835
+ "type": "varchar(191)",
836
+ "typeSchema": null,
837
+ "notNull": false,
838
+ "dimensions": 0,
839
+ "default": null,
840
+ "generated": null,
841
+ "identity": null,
842
+ "name": "tunnel_id",
843
+ "entityType": "columns",
844
+ "schema": "public",
845
+ "table": "relay_managed_endpoint_allocations"
846
+ },
847
+ {
848
+ "type": "text",
849
+ "typeSchema": null,
850
+ "notNull": true,
851
+ "dimensions": 0,
852
+ "default": null,
853
+ "generated": null,
854
+ "identity": null,
855
+ "name": "tunnel_name",
856
+ "entityType": "columns",
857
+ "schema": "public",
858
+ "table": "relay_managed_endpoint_allocations"
859
+ },
860
+ {
861
+ "type": "varchar(191)",
862
+ "typeSchema": null,
863
+ "notNull": false,
864
+ "dimensions": 0,
865
+ "default": null,
866
+ "generated": null,
867
+ "identity": null,
868
+ "name": "dns_record_id",
869
+ "entityType": "columns",
870
+ "schema": "public",
871
+ "table": "relay_managed_endpoint_allocations"
872
+ },
873
+ {
874
+ "type": "varchar(64)",
875
+ "typeSchema": null,
876
+ "notNull": false,
877
+ "dimensions": 0,
878
+ "default": null,
879
+ "generated": null,
880
+ "identity": null,
881
+ "name": "ready_at",
882
+ "entityType": "columns",
883
+ "schema": "public",
884
+ "table": "relay_managed_endpoint_allocations"
885
+ },
886
+ {
887
+ "type": "varchar(64)",
888
+ "typeSchema": null,
889
+ "notNull": false,
890
+ "dimensions": 0,
891
+ "default": null,
892
+ "generated": null,
893
+ "identity": null,
894
+ "name": "recovery_enabled_at",
895
+ "entityType": "columns",
896
+ "schema": "public",
897
+ "table": "relay_managed_endpoint_allocations"
898
+ },
899
+ {
900
+ "type": "text",
901
+ "typeSchema": null,
902
+ "notNull": false,
903
+ "dimensions": 0,
904
+ "default": null,
905
+ "generated": null,
906
+ "identity": null,
907
+ "name": "recovery_environment_public_key",
908
+ "entityType": "columns",
909
+ "schema": "public",
910
+ "table": "relay_managed_endpoint_allocations"
911
+ },
912
+ {
913
+ "type": "varchar(64)",
914
+ "typeSchema": null,
915
+ "notNull": false,
916
+ "dimensions": 0,
917
+ "default": null,
918
+ "generated": null,
919
+ "identity": null,
920
+ "name": "tunnel_released_at",
921
+ "entityType": "columns",
922
+ "schema": "public",
923
+ "table": "relay_managed_endpoint_allocations"
924
+ },
925
+ {
926
+ "type": "jsonb",
927
+ "typeSchema": null,
928
+ "notNull": false,
929
+ "dimensions": 0,
930
+ "default": null,
931
+ "generated": null,
932
+ "identity": null,
933
+ "name": "origin",
934
+ "entityType": "columns",
935
+ "schema": "public",
936
+ "table": "relay_managed_endpoint_allocations"
937
+ },
938
+ {
939
+ "type": "integer",
940
+ "typeSchema": null,
941
+ "notNull": true,
942
+ "dimensions": 0,
943
+ "default": "0",
944
+ "generated": null,
945
+ "identity": null,
946
+ "name": "generation",
947
+ "entityType": "columns",
948
+ "schema": "public",
949
+ "table": "relay_managed_endpoint_allocations"
950
+ },
951
+ {
952
+ "type": "varchar(64)",
953
+ "typeSchema": null,
954
+ "notNull": true,
955
+ "dimensions": 0,
956
+ "default": null,
957
+ "generated": null,
958
+ "identity": null,
959
+ "name": "created_at",
960
+ "entityType": "columns",
961
+ "schema": "public",
962
+ "table": "relay_managed_endpoint_allocations"
963
+ },
964
+ {
965
+ "type": "varchar(64)",
966
+ "typeSchema": null,
967
+ "notNull": true,
968
+ "dimensions": 0,
969
+ "default": null,
970
+ "generated": null,
971
+ "identity": null,
972
+ "name": "updated_at",
973
+ "entityType": "columns",
974
+ "schema": "public",
975
+ "table": "relay_managed_endpoint_allocations"
976
+ },
977
+ {
978
+ "type": "varchar(191)",
979
+ "typeSchema": null,
980
+ "notNull": true,
981
+ "dimensions": 0,
982
+ "default": null,
983
+ "generated": null,
984
+ "identity": null,
985
+ "name": "user_id",
986
+ "entityType": "columns",
987
+ "schema": "public",
988
+ "table": "relay_managed_tunnel_limits"
989
+ },
990
+ {
991
+ "type": "integer",
992
+ "typeSchema": null,
993
+ "notNull": true,
994
+ "dimensions": 0,
995
+ "default": null,
996
+ "generated": null,
997
+ "identity": null,
998
+ "name": "max_tunnels",
999
+ "entityType": "columns",
1000
+ "schema": "public",
1001
+ "table": "relay_managed_tunnel_limits"
1002
+ },
1003
+ {
1004
+ "type": "varchar(64)",
1005
+ "typeSchema": null,
1006
+ "notNull": true,
1007
+ "dimensions": 0,
1008
+ "default": null,
1009
+ "generated": null,
1010
+ "identity": null,
1011
+ "name": "created_at",
1012
+ "entityType": "columns",
1013
+ "schema": "public",
1014
+ "table": "relay_managed_tunnel_limits"
1015
+ },
1016
+ {
1017
+ "type": "varchar(64)",
1018
+ "typeSchema": null,
1019
+ "notNull": true,
1020
+ "dimensions": 0,
1021
+ "default": null,
1022
+ "generated": null,
1023
+ "identity": null,
1024
+ "name": "updated_at",
1025
+ "entityType": "columns",
1026
+ "schema": "public",
1027
+ "table": "relay_managed_tunnel_limits"
1028
+ },
1029
+ {
1030
+ "type": "varchar(255)",
1031
+ "typeSchema": null,
1032
+ "notNull": true,
1033
+ "dimensions": 0,
1034
+ "default": null,
1035
+ "generated": null,
1036
+ "identity": null,
1037
+ "name": "user_id",
1038
+ "entityType": "columns",
1039
+ "schema": "public",
1040
+ "table": "relay_mobile_devices"
1041
+ },
1042
+ {
1043
+ "type": "varchar(255)",
1044
+ "typeSchema": null,
1045
+ "notNull": true,
1046
+ "dimensions": 0,
1047
+ "default": null,
1048
+ "generated": null,
1049
+ "identity": null,
1050
+ "name": "device_id",
1051
+ "entityType": "columns",
1052
+ "schema": "public",
1053
+ "table": "relay_mobile_devices"
1054
+ },
1055
+ {
1056
+ "type": "text",
1057
+ "typeSchema": null,
1058
+ "notNull": true,
1059
+ "dimensions": 0,
1060
+ "default": "'iOS device'",
1061
+ "generated": null,
1062
+ "identity": null,
1063
+ "name": "label",
1064
+ "entityType": "columns",
1065
+ "schema": "public",
1066
+ "table": "relay_mobile_devices"
1067
+ },
1068
+ {
1069
+ "type": "varchar(16)",
1070
+ "typeSchema": null,
1071
+ "notNull": true,
1072
+ "dimensions": 0,
1073
+ "default": null,
1074
+ "generated": null,
1075
+ "identity": null,
1076
+ "name": "platform",
1077
+ "entityType": "columns",
1078
+ "schema": "public",
1079
+ "table": "relay_mobile_devices"
1080
+ },
1081
+ {
1082
+ "type": "integer",
1083
+ "typeSchema": null,
1084
+ "notNull": false,
1085
+ "dimensions": 0,
1086
+ "default": null,
1087
+ "generated": null,
1088
+ "identity": null,
1089
+ "name": "ios_major_version",
1090
+ "entityType": "columns",
1091
+ "schema": "public",
1092
+ "table": "relay_mobile_devices"
1093
+ },
1094
+ {
1095
+ "type": "integer",
1096
+ "typeSchema": null,
1097
+ "notNull": false,
1098
+ "dimensions": 0,
1099
+ "default": null,
1100
+ "generated": null,
1101
+ "identity": null,
1102
+ "name": "android_api_level",
1103
+ "entityType": "columns",
1104
+ "schema": "public",
1105
+ "table": "relay_mobile_devices"
1106
+ },
1107
+ {
1108
+ "type": "varchar(64)",
1109
+ "typeSchema": null,
1110
+ "notNull": false,
1111
+ "dimensions": 0,
1112
+ "default": null,
1113
+ "generated": null,
1114
+ "identity": null,
1115
+ "name": "app_version",
1116
+ "entityType": "columns",
1117
+ "schema": "public",
1118
+ "table": "relay_mobile_devices"
1119
+ },
1120
+ {
1121
+ "type": "varchar(255)",
1122
+ "typeSchema": null,
1123
+ "notNull": false,
1124
+ "dimensions": 0,
1125
+ "default": null,
1126
+ "generated": null,
1127
+ "identity": null,
1128
+ "name": "bundle_id",
1129
+ "entityType": "columns",
1130
+ "schema": "public",
1131
+ "table": "relay_mobile_devices"
1132
+ },
1133
+ {
1134
+ "type": "varchar(16)",
1135
+ "typeSchema": null,
1136
+ "notNull": false,
1137
+ "dimensions": 0,
1138
+ "default": null,
1139
+ "generated": null,
1140
+ "identity": null,
1141
+ "name": "aps_environment",
1142
+ "entityType": "columns",
1143
+ "schema": "public",
1144
+ "table": "relay_mobile_devices"
1145
+ },
1146
+ {
1147
+ "type": "text",
1148
+ "typeSchema": null,
1149
+ "notNull": false,
1150
+ "dimensions": 0,
1151
+ "default": null,
1152
+ "generated": null,
1153
+ "identity": null,
1154
+ "name": "push_token",
1155
+ "entityType": "columns",
1156
+ "schema": "public",
1157
+ "table": "relay_mobile_devices"
1158
+ },
1159
+ {
1160
+ "type": "text",
1161
+ "typeSchema": null,
1162
+ "notNull": false,
1163
+ "dimensions": 0,
1164
+ "default": null,
1165
+ "generated": null,
1166
+ "identity": null,
1167
+ "name": "push_to_start_token",
1168
+ "entityType": "columns",
1169
+ "schema": "public",
1170
+ "table": "relay_mobile_devices"
1171
+ },
1172
+ {
1173
+ "type": "jsonb",
1174
+ "typeSchema": null,
1175
+ "notNull": true,
1176
+ "dimensions": 0,
1177
+ "default": null,
1178
+ "generated": null,
1179
+ "identity": null,
1180
+ "name": "preferences_json",
1181
+ "entityType": "columns",
1182
+ "schema": "public",
1183
+ "table": "relay_mobile_devices"
1184
+ },
1185
+ {
1186
+ "type": "varchar(64)",
1187
+ "typeSchema": null,
1188
+ "notNull": true,
1189
+ "dimensions": 0,
1190
+ "default": null,
1191
+ "generated": null,
1192
+ "identity": null,
1193
+ "name": "created_at",
1194
+ "entityType": "columns",
1195
+ "schema": "public",
1196
+ "table": "relay_mobile_devices"
1197
+ },
1198
+ {
1199
+ "type": "varchar(64)",
1200
+ "typeSchema": null,
1201
+ "notNull": true,
1202
+ "dimensions": 0,
1203
+ "default": null,
1204
+ "generated": null,
1205
+ "identity": null,
1206
+ "name": "updated_at",
1207
+ "entityType": "columns",
1208
+ "schema": "public",
1209
+ "table": "relay_mobile_devices"
1210
+ },
1211
+ {
1212
+ "type": "varchar(64)",
1213
+ "typeSchema": null,
1214
+ "notNull": true,
1215
+ "dimensions": 0,
1216
+ "default": null,
1217
+ "generated": null,
1218
+ "identity": null,
1219
+ "name": "api",
1220
+ "entityType": "columns",
1221
+ "schema": "public",
1222
+ "table": "relay_upstream_api_pauses"
1223
+ },
1224
+ {
1225
+ "type": "bigint",
1226
+ "typeSchema": null,
1227
+ "notNull": true,
1228
+ "dimensions": 0,
1229
+ "default": null,
1230
+ "generated": null,
1231
+ "identity": null,
1232
+ "name": "paused_until_ms",
1233
+ "entityType": "columns",
1234
+ "schema": "public",
1235
+ "table": "relay_upstream_api_pauses"
1236
+ },
1237
+ {
1238
+ "nameExplicit": true,
1239
+ "columns": [
1240
+ {
1241
+ "value": "created_at",
1242
+ "isExpression": false,
1243
+ "asc": true,
1244
+ "nullsFirst": false,
1245
+ "opclass": null
1246
+ }
1247
+ ],
1248
+ "isUnique": false,
1249
+ "where": null,
1250
+ "with": "",
1251
+ "method": "btree",
1252
+ "concurrently": false,
1253
+ "name": "idx_relay_delivery_attempts_created",
1254
+ "entityType": "indexes",
1255
+ "schema": "public",
1256
+ "table": "relay_delivery_attempts"
1257
+ },
1258
+ {
1259
+ "nameExplicit": true,
1260
+ "columns": [
1261
+ {
1262
+ "value": "source_job_id",
1263
+ "isExpression": false,
1264
+ "asc": true,
1265
+ "nullsFirst": false,
1266
+ "opclass": null
1267
+ }
1268
+ ],
1269
+ "isUnique": true,
1270
+ "where": null,
1271
+ "with": "",
1272
+ "method": "btree",
1273
+ "concurrently": false,
1274
+ "name": "idx_relay_delivery_attempts_source_job",
1275
+ "entityType": "indexes",
1276
+ "schema": "public",
1277
+ "table": "relay_delivery_attempts"
1278
+ },
1279
+ {
1280
+ "nameExplicit": true,
1281
+ "columns": [
1282
+ {
1283
+ "value": "expires_at",
1284
+ "isExpression": false,
1285
+ "asc": true,
1286
+ "nullsFirst": false,
1287
+ "opclass": null
1288
+ }
1289
+ ],
1290
+ "isUnique": false,
1291
+ "where": null,
1292
+ "with": "",
1293
+ "method": "btree",
1294
+ "concurrently": false,
1295
+ "name": "idx_relay_dpop_proofs_expires_at",
1296
+ "entityType": "indexes",
1297
+ "schema": "public",
1298
+ "table": "relay_dpop_proofs"
1299
+ },
1300
+ {
1301
+ "nameExplicit": true,
1302
+ "columns": [
1303
+ {
1304
+ "value": "credential_hash",
1305
+ "isExpression": false,
1306
+ "asc": true,
1307
+ "nullsFirst": false,
1308
+ "opclass": null
1309
+ }
1310
+ ],
1311
+ "isUnique": true,
1312
+ "where": null,
1313
+ "with": "",
1314
+ "method": "btree",
1315
+ "concurrently": false,
1316
+ "name": "idx_relay_environment_credentials_hash",
1317
+ "entityType": "indexes",
1318
+ "schema": "public",
1319
+ "table": "relay_environment_credentials"
1320
+ },
1321
+ {
1322
+ "nameExplicit": true,
1323
+ "columns": [
1324
+ {
1325
+ "value": "environment_id",
1326
+ "isExpression": false,
1327
+ "asc": true,
1328
+ "nullsFirst": false,
1329
+ "opclass": null
1330
+ },
1331
+ {
1332
+ "value": "environment_public_key",
1333
+ "isExpression": false,
1334
+ "asc": true,
1335
+ "nullsFirst": false,
1336
+ "opclass": null
1337
+ },
1338
+ {
1339
+ "value": "revoked_at",
1340
+ "isExpression": false,
1341
+ "asc": true,
1342
+ "nullsFirst": false,
1343
+ "opclass": null
1344
+ }
1345
+ ],
1346
+ "isUnique": false,
1347
+ "where": null,
1348
+ "with": "",
1349
+ "method": "btree",
1350
+ "concurrently": false,
1351
+ "name": "idx_relay_environment_credentials_environment_key",
1352
+ "entityType": "indexes",
1353
+ "schema": "public",
1354
+ "table": "relay_environment_credentials"
1355
+ },
1356
+ {
1357
+ "nameExplicit": true,
1358
+ "columns": [
1359
+ {
1360
+ "value": "environment_id",
1361
+ "isExpression": false,
1362
+ "asc": true,
1363
+ "nullsFirst": false,
1364
+ "opclass": null
1365
+ },
1366
+ {
1367
+ "value": "revoked_at",
1368
+ "isExpression": false,
1369
+ "asc": true,
1370
+ "nullsFirst": false,
1371
+ "opclass": null
1372
+ }
1373
+ ],
1374
+ "isUnique": false,
1375
+ "where": null,
1376
+ "with": "",
1377
+ "method": "btree",
1378
+ "concurrently": false,
1379
+ "name": "idx_relay_environment_links_environment",
1380
+ "entityType": "indexes",
1381
+ "schema": "public",
1382
+ "table": "relay_environment_links"
1383
+ },
1384
+ {
1385
+ "nameExplicit": true,
1386
+ "columns": [
1387
+ {
1388
+ "value": "activity_push_token",
1389
+ "isExpression": false,
1390
+ "asc": true,
1391
+ "nullsFirst": false,
1392
+ "opclass": null
1393
+ }
1394
+ ],
1395
+ "isUnique": true,
1396
+ "where": null,
1397
+ "with": "",
1398
+ "method": "btree",
1399
+ "concurrently": false,
1400
+ "name": "idx_relay_live_activities_activity_push_token",
1401
+ "entityType": "indexes",
1402
+ "schema": "public",
1403
+ "table": "relay_live_activities"
1404
+ },
1405
+ {
1406
+ "nameExplicit": true,
1407
+ "columns": [
1408
+ {
1409
+ "value": "hostname",
1410
+ "isExpression": false,
1411
+ "asc": true,
1412
+ "nullsFirst": false,
1413
+ "opclass": null
1414
+ }
1415
+ ],
1416
+ "isUnique": true,
1417
+ "where": null,
1418
+ "with": "",
1419
+ "method": "btree",
1420
+ "concurrently": false,
1421
+ "name": "idx_relay_managed_endpoint_allocations_hostname",
1422
+ "entityType": "indexes",
1423
+ "schema": "public",
1424
+ "table": "relay_managed_endpoint_allocations"
1425
+ },
1426
+ {
1427
+ "nameExplicit": true,
1428
+ "columns": [
1429
+ {
1430
+ "value": "tunnel_name",
1431
+ "isExpression": false,
1432
+ "asc": true,
1433
+ "nullsFirst": false,
1434
+ "opclass": null
1435
+ }
1436
+ ],
1437
+ "isUnique": true,
1438
+ "where": null,
1439
+ "with": "",
1440
+ "method": "btree",
1441
+ "concurrently": false,
1442
+ "name": "idx_relay_managed_endpoint_allocations_tunnel_name",
1443
+ "entityType": "indexes",
1444
+ "schema": "public",
1445
+ "table": "relay_managed_endpoint_allocations"
1446
+ },
1447
+ {
1448
+ "nameExplicit": true,
1449
+ "columns": [
1450
+ {
1451
+ "value": "push_token",
1452
+ "isExpression": false,
1453
+ "asc": true,
1454
+ "nullsFirst": false,
1455
+ "opclass": null
1456
+ }
1457
+ ],
1458
+ "isUnique": true,
1459
+ "where": null,
1460
+ "with": "",
1461
+ "method": "btree",
1462
+ "concurrently": false,
1463
+ "name": "idx_relay_mobile_devices_push_token",
1464
+ "entityType": "indexes",
1465
+ "schema": "public",
1466
+ "table": "relay_mobile_devices"
1467
+ },
1468
+ {
1469
+ "nameExplicit": true,
1470
+ "columns": [
1471
+ {
1472
+ "value": "push_to_start_token",
1473
+ "isExpression": false,
1474
+ "asc": true,
1475
+ "nullsFirst": false,
1476
+ "opclass": null
1477
+ }
1478
+ ],
1479
+ "isUnique": true,
1480
+ "where": null,
1481
+ "with": "",
1482
+ "method": "btree",
1483
+ "concurrently": false,
1484
+ "name": "idx_relay_mobile_devices_push_to_start_token",
1485
+ "entityType": "indexes",
1486
+ "schema": "public",
1487
+ "table": "relay_mobile_devices"
1488
+ },
1489
+ {
1490
+ "columns": ["environment_id", "environment_public_key", "thread_id"],
1491
+ "nameExplicit": false,
1492
+ "name": "relay_agent_activity_rows_pkey",
1493
+ "entityType": "pks",
1494
+ "schema": "public",
1495
+ "table": "relay_agent_activity_rows"
1496
+ },
1497
+ {
1498
+ "columns": ["thumbprint", "jti"],
1499
+ "nameExplicit": false,
1500
+ "name": "relay_dpop_proofs_pkey",
1501
+ "entityType": "pks",
1502
+ "schema": "public",
1503
+ "table": "relay_dpop_proofs"
1504
+ },
1505
+ {
1506
+ "columns": ["user_id", "environment_id"],
1507
+ "nameExplicit": false,
1508
+ "name": "relay_environment_links_pkey",
1509
+ "entityType": "pks",
1510
+ "schema": "public",
1511
+ "table": "relay_environment_links"
1512
+ },
1513
+ {
1514
+ "columns": ["user_id", "device_id"],
1515
+ "nameExplicit": false,
1516
+ "name": "relay_live_activities_pkey",
1517
+ "entityType": "pks",
1518
+ "schema": "public",
1519
+ "table": "relay_live_activities"
1520
+ },
1521
+ {
1522
+ "columns": ["user_id", "environment_id"],
1523
+ "nameExplicit": false,
1524
+ "name": "relay_managed_endpoint_allocations_pkey",
1525
+ "entityType": "pks",
1526
+ "schema": "public",
1527
+ "table": "relay_managed_endpoint_allocations"
1528
+ },
1529
+ {
1530
+ "columns": ["user_id", "device_id"],
1531
+ "nameExplicit": false,
1532
+ "name": "relay_mobile_devices_pkey",
1533
+ "entityType": "pks",
1534
+ "schema": "public",
1535
+ "table": "relay_mobile_devices"
1536
+ },
1537
+ {
1538
+ "columns": ["id"],
1539
+ "nameExplicit": false,
1540
+ "name": "relay_delivery_attempts_pkey",
1541
+ "schema": "public",
1542
+ "table": "relay_delivery_attempts",
1543
+ "entityType": "pks"
1544
+ },
1545
+ {
1546
+ "columns": ["credential_id"],
1547
+ "nameExplicit": false,
1548
+ "name": "relay_environment_credentials_pkey",
1549
+ "schema": "public",
1550
+ "table": "relay_environment_credentials",
1551
+ "entityType": "pks"
1552
+ },
1553
+ {
1554
+ "columns": ["user_id"],
1555
+ "nameExplicit": false,
1556
+ "name": "relay_managed_tunnel_limits_pkey",
1557
+ "schema": "public",
1558
+ "table": "relay_managed_tunnel_limits",
1559
+ "entityType": "pks"
1560
+ },
1561
+ {
1562
+ "columns": ["api"],
1563
+ "nameExplicit": false,
1564
+ "name": "relay_upstream_api_pauses_pkey",
1565
+ "schema": "public",
1566
+ "table": "relay_upstream_api_pauses",
1567
+ "entityType": "pks"
1568
+ }
1569
+ ],
1570
+ "renames": []
1571
+}
infra/relay/src/agentActivity/ApnsDeliveries.test.ts
+1
@@ -190,6 +190,7 @@ function layerFor(input: {
190
}),
191
}),
192
Layer.succeed(DeliveryAttempts.DeliveryAttempts, {
193
+ pruneExpired: Effect.succeed(0),
194
record: (attempt) =>
195
Effect.sync(() => {
196
input.attempts.push(attempt);
infra/relay/src/agentActivity/DeliveryAttempts.test.ts
+69
@@ -1,7 +1,9 @@
1
import * as NodeCryptoLayer from "@effect/platform-node/NodeCrypto";
2
import { describe, expect, it } from "@effect/vitest";
3
+import * as Drizzle from "@alchemy.run/drizzle/Postgres";
4
import * as Effect from "effect/Effect";
5
import * as Layer from "effect/Layer";
6
+import * as Redacted from "effect/Redacted";
7
8
import * as RelayDb from "../db.ts";
9
import * as DeliveryAttempts from "./DeliveryAttempts.ts";
@@ -168,4 +170,71 @@ describe("DeliveryAttempts", () => {
170
),
171
);
172
});
173
+
174
+ const pruneWith = (batches: ReadonlyArray<number>) => {
175
+ const deleteCalls: number[] = [];
176
+ const fakeDb = {
177
+ delete: () => ({
178
+ where: () => ({
179
+ returning: () => {
180
+ const size = batches[deleteCalls.length] ?? 0;
181
+ deleteCalls.push(size);
182
+ return Effect.succeed(Array.from({ length: size }, (_, index) => ({ id: `${index}` })));
183
+ },
184
+ }),
185
+ }),
186
+ } as unknown as RelayDb.RelayDb["Service"];
187
+ const run = DeliveryAttempts.DeliveryAttempts.pipe(
188
+ Effect.flatMap((attempts) => attempts.pruneExpired),
189
+ Effect.provide(
190
+ DeliveryAttempts.layer.pipe(
191
+ Layer.provide(NodeCryptoLayer.layer),
192
+ Layer.provide(Layer.succeed(RelayDb.RelayDb, fakeDb)),
193
+ ),
194
+ ),
195
+ );
196
+ return { run, deleteCalls };
197
+ };
198
+
199
+ it.effect("stops pruning once a batch comes back short", () => {
200
+ const full = DeliveryAttempts.DELIVERY_ATTEMPT_PRUNE_BATCH_SIZE;
201
+ const { run, deleteCalls } = pruneWith([full, 12]);
202
+ return Effect.gen(function* () {
203
+ expect(yield* run).toBe(full + 12);
204
+ expect(deleteCalls).toEqual([full, 12]);
205
+ });
206
+ });
207
+
208
+ it.effect("caps each run at the batch limit while a backlog remains", () => {
209
+ const full = DeliveryAttempts.DELIVERY_ATTEMPT_PRUNE_BATCH_SIZE;
210
+ const { run, deleteCalls } = pruneWith(Array.from({ length: 10 }, () => full));
211
+ return Effect.gen(function* () {
212
+ expect(yield* run).toBe(full * DeliveryAttempts.DELIVERY_ATTEMPT_PRUNE_MAX_BATCHES);
213
+ expect(deleteCalls).toHaveLength(DeliveryAttempts.DELIVERY_ATTEMPT_PRUNE_MAX_BATCHES);
214
+ });
215
+ });
216
+
217
+ // The Worker's db is Alchemy's proxyChain, whose builders render as nothing inside another
218
+ // query. Nothing listens on the port; the failed query still reports the SQL it sent.
219
+ it.live("prunes with a subquery the Worker's proxied database can render", () =>
220
+ Effect.gen(function* () {
221
+ const db = yield* Drizzle.Postgres(
222
+ Effect.succeed(Redacted.make("postgres://relay:relay@127.0.0.1:1/relay")),
223
+ { client: { prepare: false } },
224
+ );
225
+ const error = yield* DeliveryAttempts.DeliveryAttempts.pipe(
226
+ Effect.flatMap((attempts) => attempts.pruneExpired),
227
+ Effect.provide(
228
+ DeliveryAttempts.layer.pipe(
229
+ Layer.provide(NodeCryptoLayer.layer),
230
+ Layer.provide(Layer.succeed(RelayDb.RelayDb, db)),
231
+ ),
232
+ ),
233
+ Effect.flip,
234
+ );
235
+ expect((error.cause as { readonly query: string }).query).toMatch(
236
+ /"relay_delivery_attempts"\."id" in \(select "id" from "relay_delivery_attempts" where "relay_delivery_attempts"\."created_at" < \$1 limit \$2\)/,
237
+ );
238
+ }).pipe(Effect.scoped),
239
+ );
240
});
infra/relay/src/agentActivity/DeliveryAttempts.ts
+56
-2
@@ -3,7 +3,8 @@ import * as DateTime from "effect/DateTime";
3
import * as Effect from "effect/Effect";
4
import * as Layer from "effect/Layer";
5
import * as Option from "effect/Option";
6
-import { and, eq, isNull } from "drizzle-orm";
6
+import { and, eq, inArray, isNull, lt } from "drizzle-orm";
7
+import { QueryBuilder } from "drizzle-orm/pg-core";
8
import * as Crypto from "effect/Crypto";
9
import * as Schema from "effect/Schema";
10
@@ -13,7 +14,12 @@ import { relayDeliveryAttempts } from "../persistence/schema.ts";
14
export class DeliveryAttemptRecordPersistenceError extends Schema.TaggedError<DeliveryAttemptRecordPersistenceError>()(
15
"DeliveryAttemptRecordPersistenceError",
16
{
16
- operation: Schema.Literals(["record", "claim-source-job", "complete-source-job"]),
17
+ operation: Schema.Literals([
18
+ "record",
19
+ "claim-source-job",
20
+ "complete-source-job",
21
+ "prune-expired",
22
+ ]),
23
sourceJobId: Schema.NullOr(Schema.String),
24
userId: Schema.NullOr(Schema.String),
25
environmentId: Schema.NullOr(Schema.String),
@@ -64,10 +70,16 @@ export class DeliveryAttempts extends Context.Service<
70
readonly completeSourceJob: (
71
input: DeliveryAttemptCompletionInput,
72
) => Effect.Effect<void, DeliveryAttemptRecordPersistenceError>;
73
+ /** Delete attempts untouched for the retention period; returns how many were removed. */
74
+ readonly pruneExpired: Effect.Effect<number, DeliveryAttemptRecordPersistenceError>;
75
}
76
>()("t3code-relay/agentActivity/DeliveryAttempts") {}
77
78
const SOURCE_JOB_CLAIM_LEASE_MINUTES = 10;
79
+export const DELIVERY_ATTEMPT_RETENTION_DAYS = 7;
80
+export const DELIVERY_ATTEMPT_PRUNE_BATCH_SIZE = 5_000;
81
+// Caps each cron run so draining the pre-retention backlog cannot monopolize the database.
82
+export const DELIVERY_ATTEMPT_PRUNE_MAX_BATCHES = 4;
83
84
function insertValues(
85
input: DeliveryAttemptInput,
@@ -246,6 +258,48 @@ export const make = Effect.gen(function* () {
258
),
259
);
260
}),
261
+ pruneExpired: Effect.gen(function* () {
262
+ const before = DateTime.formatIso(
263
+ DateTime.subtract(yield* DateTime.now, { days: DELIVERY_ATTEMPT_RETENTION_DAYS }),
264
+ );
265
+ yield* Effect.annotateCurrentSpan({ "relay.delivery_attempts_prune.before": before });
266
+ let deleted = 0;
267
+ for (let batch = 0; batch < DELIVERY_ATTEMPT_PRUNE_MAX_BATCHES; batch += 1) {
268
+ const rows = yield* db
269
+ .delete(relayDeliveryAttempts)
270
+ .where(
271
+ inArray(
272
+ relayDeliveryAttempts.id,
273
+ // The Worker's db is a proxy whose builders render as nothing inside another query.
274
+ new QueryBuilder()
275
+ .select({ id: relayDeliveryAttempts.id })
276
+ .from(relayDeliveryAttempts)
277
+ .where(lt(relayDeliveryAttempts.createdAt, before))
278
+ .limit(DELIVERY_ATTEMPT_PRUNE_BATCH_SIZE),
279
+ ),
280
+ )
281
+ .returning({ id: relayDeliveryAttempts.id });
282
+ deleted += rows.length;
283
+ if (rows.length < DELIVERY_ATTEMPT_PRUNE_BATCH_SIZE) break;
284
+ }
285
+ yield* Effect.annotateCurrentSpan({ "relay.delivery_attempts_prune.deleted": deleted });
286
+ return deleted;
287
+ }).pipe(
288
+ Effect.mapError(
289
+ (cause) =>
290
+ new DeliveryAttemptRecordPersistenceError({
291
+ operation: "prune-expired",
292
+ sourceJobId: null,
293
+ userId: null,
294
+ environmentId: null,
295
+ threadId: null,
296
+ deviceId: null,
297
+ kind: null,
298
+ cause,
299
+ }),
300
+ ),
301
+ Effect.withSpan("relay.delivery_attempts.prune_expired"),
302
+ ),
303
});
304
});
305
infra/relay/src/agentActivity/MobileRegistrations.test.ts
+1
@@ -131,6 +131,7 @@ function makeDeliveryAttempts(
131
record: () => Effect.void,
132
claimSourceJob: () => Effect.succeed("claimed"),
133
completeSourceJob: () => Effect.void,
134
+ pruneExpired: Effect.succeed(0),
135
...overrides,
136
};
137
}
infra/relay/src/persistence/schema.ts
+1
-7
@@ -139,7 +139,6 @@ export const relayEnvironmentCredentials = pgTable(
139
},
140
(table) => [
141
uniqueIndex("idx_relay_environment_credentials_hash").on(table.credentialHash),
142
- index("idx_relay_environment_credentials_environment").on(table.environmentId, table.revokedAt),
142
index("idx_relay_environment_credentials_environment_key").on(
143
table.environmentId,
144
table.environmentPublicKey,
@@ -160,7 +159,6 @@ export const relayAgentActivityRows = pgTable(
159
},
160
(table) => [
161
primaryKey({ columns: [table.environmentId, table.environmentPublicKey, table.threadId] }),
163
- index("idx_relay_agent_activity_rows_updated").on(table.updatedAt),
162
],
163
);
164
@@ -182,11 +180,7 @@ export const relayDeliveryAttempts = pgTable(
180
transportError: text("transport_error"),
181
},
182
(table) => [
185
- index("idx_relay_delivery_attempts_environment").on(
186
- table.environmentId,
187
- table.threadId,
188
- table.createdAt,
189
- ),
183
+ index("idx_relay_delivery_attempts_created").on(table.createdAt),
184
uniqueIndex("idx_relay_delivery_attempts_source_job").on(table.sourceJobId),
185
],
186
);
infra/relay/src/worker.ts
+5
@@ -481,6 +481,11 @@ export const layer = Api.make(
481
),
482
),
483
),
484
+ Effect.andThen(
485
+ DeliveryAttempts.DeliveryAttempts.pipe(
486
+ Effect.flatMap((attempts) => attempts.pruneExpired),
487
+ ),
488
+ ),
489
Effect.catchCause((cause) =>
490
Cause.hasInterrupts(cause)
491
? Effect.interrupt