@secondlayer/shared 6.4.0 → 6.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -789,7 +789,9 @@ type InsertSubscriptionOutbox = Insertable<SubscriptionOutboxTable>;
789
789
  type UpdateSubscriptionOutbox = Updateable<SubscriptionOutboxTable>;
790
790
  interface SubscriptionDeliveriesTable {
791
791
  id: Generated<string>;
792
- outbox_id: string;
792
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
793
+ * delivery telemetry is retained. */
794
+ outbox_id: string | null;
793
795
  subscription_id: string;
794
796
  attempt: number;
795
797
  status_code: number | null;
@@ -702,7 +702,9 @@ interface SubscriptionOutboxTable {
702
702
  }
703
703
  interface SubscriptionDeliveriesTable {
704
704
  id: Generated<string>;
705
- outbox_id: string;
705
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
706
+ * delivery telemetry is retained. */
707
+ outbox_id: string | null;
706
708
  subscription_id: string;
707
709
  attempt: number;
708
710
  status_code: number | null;
@@ -700,7 +700,9 @@ interface SubscriptionOutboxTable {
700
700
  }
701
701
  interface SubscriptionDeliveriesTable {
702
702
  id: Generated<string>;
703
- outbox_id: string;
703
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
704
+ * delivery telemetry is retained. */
705
+ outbox_id: string | null;
704
706
  subscription_id: string;
705
707
  attempt: number;
706
708
  status_code: number | null;
@@ -702,7 +702,9 @@ interface SubscriptionOutboxTable {
702
702
  }
703
703
  interface SubscriptionDeliveriesTable {
704
704
  id: Generated<string>;
705
- outbox_id: string;
705
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
706
+ * delivery telemetry is retained. */
707
+ outbox_id: string | null;
706
708
  subscription_id: string;
707
709
  attempt: number;
708
710
  status_code: number | null;
@@ -699,7 +699,9 @@ interface SubscriptionOutboxTable {
699
699
  }
700
700
  interface SubscriptionDeliveriesTable {
701
701
  id: Generated<string>;
702
- outbox_id: string;
702
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
703
+ * delivery telemetry is retained. */
704
+ outbox_id: string | null;
703
705
  subscription_id: string;
704
706
  attempt: number;
705
707
  status_code: number | null;
@@ -700,7 +700,9 @@ interface SubscriptionOutboxTable {
700
700
  }
701
701
  interface SubscriptionDeliveriesTable {
702
702
  id: Generated<string>;
703
- outbox_id: string;
703
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
704
+ * delivery telemetry is retained. */
705
+ outbox_id: string | null;
704
706
  subscription_id: string;
705
707
  attempt: number;
706
708
  status_code: number | null;
@@ -702,7 +702,9 @@ interface SubscriptionOutboxTable {
702
702
  }
703
703
  interface SubscriptionDeliveriesTable {
704
704
  id: Generated<string>;
705
- outbox_id: string;
705
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
706
+ * delivery telemetry is retained. */
707
+ outbox_id: string | null;
706
708
  subscription_id: string;
707
709
  attempt: number;
708
710
  status_code: number | null;
@@ -701,7 +701,9 @@ interface SubscriptionOutboxTable {
701
701
  }
702
702
  interface SubscriptionDeliveriesTable {
703
703
  id: Generated<string>;
704
- outbox_id: string;
704
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
705
+ * delivery telemetry is retained. */
706
+ outbox_id: string | null;
705
707
  subscription_id: string;
706
708
  attempt: number;
707
709
  status_code: number | null;
@@ -700,7 +700,9 @@ interface SubscriptionOutboxTable {
700
700
  }
701
701
  interface SubscriptionDeliveriesTable {
702
702
  id: Generated<string>;
703
- outbox_id: string;
703
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
704
+ * delivery telemetry is retained. */
705
+ outbox_id: string | null;
704
706
  subscription_id: string;
705
707
  attempt: number;
706
708
  status_code: number | null;
@@ -701,7 +701,9 @@ interface SubscriptionOutboxTable {
701
701
  }
702
702
  interface SubscriptionDeliveriesTable {
703
703
  id: Generated<string>;
704
- outbox_id: string;
704
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
705
+ * delivery telemetry is retained. */
706
+ outbox_id: string | null;
705
707
  subscription_id: string;
706
708
  attempt: number;
707
709
  status_code: number | null;
@@ -701,7 +701,9 @@ interface SubscriptionOutboxTable {
701
701
  }
702
702
  interface SubscriptionDeliveriesTable {
703
703
  id: Generated<string>;
704
- outbox_id: string;
704
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
705
+ * delivery telemetry is retained. */
706
+ outbox_id: string | null;
705
707
  subscription_id: string;
706
708
  attempt: number;
707
709
  status_code: number | null;
@@ -701,7 +701,9 @@ interface SubscriptionOutboxTable {
701
701
  }
702
702
  interface SubscriptionDeliveriesTable {
703
703
  id: Generated<string>;
704
- outbox_id: string;
704
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
705
+ * delivery telemetry is retained. */
706
+ outbox_id: string | null;
705
707
  subscription_id: string;
706
708
  attempt: number;
707
709
  status_code: number | null;
@@ -701,7 +701,9 @@ interface SubscriptionOutboxTable {
701
701
  }
702
702
  interface SubscriptionDeliveriesTable {
703
703
  id: Generated<string>;
704
- outbox_id: string;
704
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
705
+ * delivery telemetry is retained. */
706
+ outbox_id: string | null;
705
707
  subscription_id: string;
706
708
  attempt: number;
707
709
  status_code: number | null;
@@ -700,7 +700,9 @@ interface SubscriptionOutboxTable {
700
700
  }
701
701
  interface SubscriptionDeliveriesTable {
702
702
  id: Generated<string>;
703
- outbox_id: string;
703
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
704
+ * delivery telemetry is retained. */
705
+ outbox_id: string | null;
704
706
  subscription_id: string;
705
707
  attempt: number;
706
708
  status_code: number | null;
@@ -770,7 +770,9 @@ type InsertSubscriptionOutbox = Insertable<SubscriptionOutboxTable>;
770
770
  type UpdateSubscriptionOutbox = Updateable<SubscriptionOutboxTable>;
771
771
  interface SubscriptionDeliveriesTable {
772
772
  id: Generated<string>;
773
- outbox_id: string;
773
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
774
+ * delivery telemetry is retained. */
775
+ outbox_id: string | null;
774
776
  subscription_id: string;
775
777
  attempt: number;
776
778
  status_code: number | null;
@@ -770,7 +770,9 @@ type InsertSubscriptionOutbox = Insertable<SubscriptionOutboxTable>;
770
770
  type UpdateSubscriptionOutbox = Updateable<SubscriptionOutboxTable>;
771
771
  interface SubscriptionDeliveriesTable {
772
772
  id: Generated<string>;
773
- outbox_id: string;
773
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
774
+ * delivery telemetry is retained. */
775
+ outbox_id: string | null;
774
776
  subscription_id: string;
775
777
  attempt: number;
776
778
  status_code: number | null;
@@ -700,7 +700,9 @@ interface SubscriptionOutboxTable {
700
700
  }
701
701
  interface SubscriptionDeliveriesTable {
702
702
  id: Generated<string>;
703
- outbox_id: string;
703
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
704
+ * delivery telemetry is retained. */
705
+ outbox_id: string | null;
704
706
  subscription_id: string;
705
707
  attempt: number;
706
708
  status_code: number | null;
@@ -0,0 +1,50 @@
1
+ import { type Kysely, sql } from "kysely";
2
+
3
+ /**
4
+ * Loosen `subscription_deliveries.outbox_id` FK from `ON DELETE CASCADE` to
5
+ * `ON DELETE SET NULL` so phantom outbox deletes (cleanup races, manual
6
+ * requeue, subscription delete mid-dispatch) don't 23503 the delivery
7
+ * insert and snowball into auto-paused subscriptions via the circuit
8
+ * breaker.
9
+ *
10
+ * Delivery rows are append-only telemetry; the subscription_id column is
11
+ * the load-bearing reference. Losing the outbox link on a small minority of
12
+ * rows is preferable to losing the entire delivery record.
13
+ */
14
+ export async function up(db: Kysely<unknown>): Promise<void> {
15
+ await sql`
16
+ ALTER TABLE subscription_deliveries
17
+ ALTER COLUMN outbox_id DROP NOT NULL
18
+ `.execute(db);
19
+
20
+ await sql`
21
+ ALTER TABLE subscription_deliveries
22
+ DROP CONSTRAINT IF EXISTS subscription_deliveries_outbox_id_fkey
23
+ `.execute(db);
24
+
25
+ await sql`
26
+ ALTER TABLE subscription_deliveries
27
+ ADD CONSTRAINT subscription_deliveries_outbox_id_fkey
28
+ FOREIGN KEY (outbox_id) REFERENCES subscription_outbox(id)
29
+ ON DELETE SET NULL
30
+ `.execute(db);
31
+ }
32
+
33
+ export async function down(db: Kysely<unknown>): Promise<void> {
34
+ await sql`
35
+ ALTER TABLE subscription_deliveries
36
+ DROP CONSTRAINT IF EXISTS subscription_deliveries_outbox_id_fkey
37
+ `.execute(db);
38
+
39
+ await sql`
40
+ ALTER TABLE subscription_deliveries
41
+ ADD CONSTRAINT subscription_deliveries_outbox_id_fkey
42
+ FOREIGN KEY (outbox_id) REFERENCES subscription_outbox(id)
43
+ ON DELETE CASCADE
44
+ `.execute(db);
45
+
46
+ await sql`
47
+ ALTER TABLE subscription_deliveries
48
+ ALTER COLUMN outbox_id SET NOT NULL
49
+ `.execute(db);
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secondlayer/shared",
3
- "version": "6.4.0",
3
+ "version": "6.4.1",
4
4
  "type": "module",
5
5
  "main": "./dist/src/index.js",
6
6
  "types": "./dist/src/index.d.ts",