@dudousxd/nestjs-durable-store-drizzle 0.26.0 → 0.28.0
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.
- package/dist/index.cjs +128 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +152 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +128 -8
- package/dist/index.js.map +1 -1
- package/dist/pg/index.cjs +130 -10
- package/dist/pg/index.cjs.map +1 -1
- package/dist/pg/index.d.cts +136 -0
- package/dist/pg/index.d.ts +136 -0
- package/dist/pg/index.js +130 -10
- package/dist/pg/index.js.map +1 -1
- package/package.json +9 -6
package/dist/pg/index.d.cts
CHANGED
|
@@ -572,6 +572,40 @@ declare const durableWorkflowRuns: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
|
572
572
|
identity: undefined;
|
|
573
573
|
generated: undefined;
|
|
574
574
|
}, {}, {}>;
|
|
575
|
+
tenantId: drizzle_orm_pg_core.PgColumn<{
|
|
576
|
+
name: "tenant_id";
|
|
577
|
+
tableName: "durable_workflow_runs";
|
|
578
|
+
dataType: "string";
|
|
579
|
+
columnType: "PgText";
|
|
580
|
+
data: string;
|
|
581
|
+
driverParam: string;
|
|
582
|
+
notNull: false;
|
|
583
|
+
hasDefault: false;
|
|
584
|
+
isPrimaryKey: false;
|
|
585
|
+
isAutoincrement: false;
|
|
586
|
+
hasRuntimeDefault: false;
|
|
587
|
+
enumValues: [string, ...string[]];
|
|
588
|
+
baseColumn: never;
|
|
589
|
+
identity: undefined;
|
|
590
|
+
generated: undefined;
|
|
591
|
+
}, {}, {}>;
|
|
592
|
+
tenantKind: drizzle_orm_pg_core.PgColumn<{
|
|
593
|
+
name: "tenant_kind";
|
|
594
|
+
tableName: "durable_workflow_runs";
|
|
595
|
+
dataType: "string";
|
|
596
|
+
columnType: "PgText";
|
|
597
|
+
data: string;
|
|
598
|
+
driverParam: string;
|
|
599
|
+
notNull: false;
|
|
600
|
+
hasDefault: false;
|
|
601
|
+
isPrimaryKey: false;
|
|
602
|
+
isAutoincrement: false;
|
|
603
|
+
hasRuntimeDefault: false;
|
|
604
|
+
enumValues: [string, ...string[]];
|
|
605
|
+
baseColumn: never;
|
|
606
|
+
identity: undefined;
|
|
607
|
+
generated: undefined;
|
|
608
|
+
}, {}, {}>;
|
|
575
609
|
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
576
610
|
name: string;
|
|
577
611
|
tableName: "durable_workflow_runs";
|
|
@@ -1392,6 +1426,40 @@ declare const durableSchedules: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
|
1392
1426
|
}, {}, {
|
|
1393
1427
|
$type: Record<string, unknown>;
|
|
1394
1428
|
}>;
|
|
1429
|
+
tenantId: drizzle_orm_pg_core.PgColumn<{
|
|
1430
|
+
name: "tenant_id";
|
|
1431
|
+
tableName: "durable_schedules";
|
|
1432
|
+
dataType: "string";
|
|
1433
|
+
columnType: "PgText";
|
|
1434
|
+
data: string;
|
|
1435
|
+
driverParam: string;
|
|
1436
|
+
notNull: false;
|
|
1437
|
+
hasDefault: false;
|
|
1438
|
+
isPrimaryKey: false;
|
|
1439
|
+
isAutoincrement: false;
|
|
1440
|
+
hasRuntimeDefault: false;
|
|
1441
|
+
enumValues: [string, ...string[]];
|
|
1442
|
+
baseColumn: never;
|
|
1443
|
+
identity: undefined;
|
|
1444
|
+
generated: undefined;
|
|
1445
|
+
}, {}, {}>;
|
|
1446
|
+
tenantKind: drizzle_orm_pg_core.PgColumn<{
|
|
1447
|
+
name: "tenant_kind";
|
|
1448
|
+
tableName: "durable_schedules";
|
|
1449
|
+
dataType: "string";
|
|
1450
|
+
columnType: "PgText";
|
|
1451
|
+
data: string;
|
|
1452
|
+
driverParam: string;
|
|
1453
|
+
notNull: false;
|
|
1454
|
+
hasDefault: false;
|
|
1455
|
+
isPrimaryKey: false;
|
|
1456
|
+
isAutoincrement: false;
|
|
1457
|
+
hasRuntimeDefault: false;
|
|
1458
|
+
enumValues: [string, ...string[]];
|
|
1459
|
+
baseColumn: never;
|
|
1460
|
+
identity: undefined;
|
|
1461
|
+
generated: undefined;
|
|
1462
|
+
}, {}, {}>;
|
|
1395
1463
|
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
1396
1464
|
name: string;
|
|
1397
1465
|
tableName: "durable_schedules";
|
|
@@ -1732,6 +1800,40 @@ declare const durablePgSchema: {
|
|
|
1732
1800
|
identity: undefined;
|
|
1733
1801
|
generated: undefined;
|
|
1734
1802
|
}, {}, {}>;
|
|
1803
|
+
tenantId: drizzle_orm_pg_core.PgColumn<{
|
|
1804
|
+
name: "tenant_id";
|
|
1805
|
+
tableName: "durable_workflow_runs";
|
|
1806
|
+
dataType: "string";
|
|
1807
|
+
columnType: "PgText";
|
|
1808
|
+
data: string;
|
|
1809
|
+
driverParam: string;
|
|
1810
|
+
notNull: false;
|
|
1811
|
+
hasDefault: false;
|
|
1812
|
+
isPrimaryKey: false;
|
|
1813
|
+
isAutoincrement: false;
|
|
1814
|
+
hasRuntimeDefault: false;
|
|
1815
|
+
enumValues: [string, ...string[]];
|
|
1816
|
+
baseColumn: never;
|
|
1817
|
+
identity: undefined;
|
|
1818
|
+
generated: undefined;
|
|
1819
|
+
}, {}, {}>;
|
|
1820
|
+
tenantKind: drizzle_orm_pg_core.PgColumn<{
|
|
1821
|
+
name: "tenant_kind";
|
|
1822
|
+
tableName: "durable_workflow_runs";
|
|
1823
|
+
dataType: "string";
|
|
1824
|
+
columnType: "PgText";
|
|
1825
|
+
data: string;
|
|
1826
|
+
driverParam: string;
|
|
1827
|
+
notNull: false;
|
|
1828
|
+
hasDefault: false;
|
|
1829
|
+
isPrimaryKey: false;
|
|
1830
|
+
isAutoincrement: false;
|
|
1831
|
+
hasRuntimeDefault: false;
|
|
1832
|
+
enumValues: [string, ...string[]];
|
|
1833
|
+
baseColumn: never;
|
|
1834
|
+
identity: undefined;
|
|
1835
|
+
generated: undefined;
|
|
1836
|
+
}, {}, {}>;
|
|
1735
1837
|
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
1736
1838
|
name: string;
|
|
1737
1839
|
tableName: "durable_workflow_runs";
|
|
@@ -2552,6 +2654,40 @@ declare const durablePgSchema: {
|
|
|
2552
2654
|
}, {}, {
|
|
2553
2655
|
$type: Record<string, unknown>;
|
|
2554
2656
|
}>;
|
|
2657
|
+
tenantId: drizzle_orm_pg_core.PgColumn<{
|
|
2658
|
+
name: "tenant_id";
|
|
2659
|
+
tableName: "durable_schedules";
|
|
2660
|
+
dataType: "string";
|
|
2661
|
+
columnType: "PgText";
|
|
2662
|
+
data: string;
|
|
2663
|
+
driverParam: string;
|
|
2664
|
+
notNull: false;
|
|
2665
|
+
hasDefault: false;
|
|
2666
|
+
isPrimaryKey: false;
|
|
2667
|
+
isAutoincrement: false;
|
|
2668
|
+
hasRuntimeDefault: false;
|
|
2669
|
+
enumValues: [string, ...string[]];
|
|
2670
|
+
baseColumn: never;
|
|
2671
|
+
identity: undefined;
|
|
2672
|
+
generated: undefined;
|
|
2673
|
+
}, {}, {}>;
|
|
2674
|
+
tenantKind: drizzle_orm_pg_core.PgColumn<{
|
|
2675
|
+
name: "tenant_kind";
|
|
2676
|
+
tableName: "durable_schedules";
|
|
2677
|
+
dataType: "string";
|
|
2678
|
+
columnType: "PgText";
|
|
2679
|
+
data: string;
|
|
2680
|
+
driverParam: string;
|
|
2681
|
+
notNull: false;
|
|
2682
|
+
hasDefault: false;
|
|
2683
|
+
isPrimaryKey: false;
|
|
2684
|
+
isAutoincrement: false;
|
|
2685
|
+
hasRuntimeDefault: false;
|
|
2686
|
+
enumValues: [string, ...string[]];
|
|
2687
|
+
baseColumn: never;
|
|
2688
|
+
identity: undefined;
|
|
2689
|
+
generated: undefined;
|
|
2690
|
+
}, {}, {}>;
|
|
2555
2691
|
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
2556
2692
|
name: string;
|
|
2557
2693
|
tableName: "durable_schedules";
|
package/dist/pg/index.d.ts
CHANGED
|
@@ -572,6 +572,40 @@ declare const durableWorkflowRuns: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
|
572
572
|
identity: undefined;
|
|
573
573
|
generated: undefined;
|
|
574
574
|
}, {}, {}>;
|
|
575
|
+
tenantId: drizzle_orm_pg_core.PgColumn<{
|
|
576
|
+
name: "tenant_id";
|
|
577
|
+
tableName: "durable_workflow_runs";
|
|
578
|
+
dataType: "string";
|
|
579
|
+
columnType: "PgText";
|
|
580
|
+
data: string;
|
|
581
|
+
driverParam: string;
|
|
582
|
+
notNull: false;
|
|
583
|
+
hasDefault: false;
|
|
584
|
+
isPrimaryKey: false;
|
|
585
|
+
isAutoincrement: false;
|
|
586
|
+
hasRuntimeDefault: false;
|
|
587
|
+
enumValues: [string, ...string[]];
|
|
588
|
+
baseColumn: never;
|
|
589
|
+
identity: undefined;
|
|
590
|
+
generated: undefined;
|
|
591
|
+
}, {}, {}>;
|
|
592
|
+
tenantKind: drizzle_orm_pg_core.PgColumn<{
|
|
593
|
+
name: "tenant_kind";
|
|
594
|
+
tableName: "durable_workflow_runs";
|
|
595
|
+
dataType: "string";
|
|
596
|
+
columnType: "PgText";
|
|
597
|
+
data: string;
|
|
598
|
+
driverParam: string;
|
|
599
|
+
notNull: false;
|
|
600
|
+
hasDefault: false;
|
|
601
|
+
isPrimaryKey: false;
|
|
602
|
+
isAutoincrement: false;
|
|
603
|
+
hasRuntimeDefault: false;
|
|
604
|
+
enumValues: [string, ...string[]];
|
|
605
|
+
baseColumn: never;
|
|
606
|
+
identity: undefined;
|
|
607
|
+
generated: undefined;
|
|
608
|
+
}, {}, {}>;
|
|
575
609
|
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
576
610
|
name: string;
|
|
577
611
|
tableName: "durable_workflow_runs";
|
|
@@ -1392,6 +1426,40 @@ declare const durableSchedules: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
|
1392
1426
|
}, {}, {
|
|
1393
1427
|
$type: Record<string, unknown>;
|
|
1394
1428
|
}>;
|
|
1429
|
+
tenantId: drizzle_orm_pg_core.PgColumn<{
|
|
1430
|
+
name: "tenant_id";
|
|
1431
|
+
tableName: "durable_schedules";
|
|
1432
|
+
dataType: "string";
|
|
1433
|
+
columnType: "PgText";
|
|
1434
|
+
data: string;
|
|
1435
|
+
driverParam: string;
|
|
1436
|
+
notNull: false;
|
|
1437
|
+
hasDefault: false;
|
|
1438
|
+
isPrimaryKey: false;
|
|
1439
|
+
isAutoincrement: false;
|
|
1440
|
+
hasRuntimeDefault: false;
|
|
1441
|
+
enumValues: [string, ...string[]];
|
|
1442
|
+
baseColumn: never;
|
|
1443
|
+
identity: undefined;
|
|
1444
|
+
generated: undefined;
|
|
1445
|
+
}, {}, {}>;
|
|
1446
|
+
tenantKind: drizzle_orm_pg_core.PgColumn<{
|
|
1447
|
+
name: "tenant_kind";
|
|
1448
|
+
tableName: "durable_schedules";
|
|
1449
|
+
dataType: "string";
|
|
1450
|
+
columnType: "PgText";
|
|
1451
|
+
data: string;
|
|
1452
|
+
driverParam: string;
|
|
1453
|
+
notNull: false;
|
|
1454
|
+
hasDefault: false;
|
|
1455
|
+
isPrimaryKey: false;
|
|
1456
|
+
isAutoincrement: false;
|
|
1457
|
+
hasRuntimeDefault: false;
|
|
1458
|
+
enumValues: [string, ...string[]];
|
|
1459
|
+
baseColumn: never;
|
|
1460
|
+
identity: undefined;
|
|
1461
|
+
generated: undefined;
|
|
1462
|
+
}, {}, {}>;
|
|
1395
1463
|
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
1396
1464
|
name: string;
|
|
1397
1465
|
tableName: "durable_schedules";
|
|
@@ -1732,6 +1800,40 @@ declare const durablePgSchema: {
|
|
|
1732
1800
|
identity: undefined;
|
|
1733
1801
|
generated: undefined;
|
|
1734
1802
|
}, {}, {}>;
|
|
1803
|
+
tenantId: drizzle_orm_pg_core.PgColumn<{
|
|
1804
|
+
name: "tenant_id";
|
|
1805
|
+
tableName: "durable_workflow_runs";
|
|
1806
|
+
dataType: "string";
|
|
1807
|
+
columnType: "PgText";
|
|
1808
|
+
data: string;
|
|
1809
|
+
driverParam: string;
|
|
1810
|
+
notNull: false;
|
|
1811
|
+
hasDefault: false;
|
|
1812
|
+
isPrimaryKey: false;
|
|
1813
|
+
isAutoincrement: false;
|
|
1814
|
+
hasRuntimeDefault: false;
|
|
1815
|
+
enumValues: [string, ...string[]];
|
|
1816
|
+
baseColumn: never;
|
|
1817
|
+
identity: undefined;
|
|
1818
|
+
generated: undefined;
|
|
1819
|
+
}, {}, {}>;
|
|
1820
|
+
tenantKind: drizzle_orm_pg_core.PgColumn<{
|
|
1821
|
+
name: "tenant_kind";
|
|
1822
|
+
tableName: "durable_workflow_runs";
|
|
1823
|
+
dataType: "string";
|
|
1824
|
+
columnType: "PgText";
|
|
1825
|
+
data: string;
|
|
1826
|
+
driverParam: string;
|
|
1827
|
+
notNull: false;
|
|
1828
|
+
hasDefault: false;
|
|
1829
|
+
isPrimaryKey: false;
|
|
1830
|
+
isAutoincrement: false;
|
|
1831
|
+
hasRuntimeDefault: false;
|
|
1832
|
+
enumValues: [string, ...string[]];
|
|
1833
|
+
baseColumn: never;
|
|
1834
|
+
identity: undefined;
|
|
1835
|
+
generated: undefined;
|
|
1836
|
+
}, {}, {}>;
|
|
1735
1837
|
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
1736
1838
|
name: string;
|
|
1737
1839
|
tableName: "durable_workflow_runs";
|
|
@@ -2552,6 +2654,40 @@ declare const durablePgSchema: {
|
|
|
2552
2654
|
}, {}, {
|
|
2553
2655
|
$type: Record<string, unknown>;
|
|
2554
2656
|
}>;
|
|
2657
|
+
tenantId: drizzle_orm_pg_core.PgColumn<{
|
|
2658
|
+
name: "tenant_id";
|
|
2659
|
+
tableName: "durable_schedules";
|
|
2660
|
+
dataType: "string";
|
|
2661
|
+
columnType: "PgText";
|
|
2662
|
+
data: string;
|
|
2663
|
+
driverParam: string;
|
|
2664
|
+
notNull: false;
|
|
2665
|
+
hasDefault: false;
|
|
2666
|
+
isPrimaryKey: false;
|
|
2667
|
+
isAutoincrement: false;
|
|
2668
|
+
hasRuntimeDefault: false;
|
|
2669
|
+
enumValues: [string, ...string[]];
|
|
2670
|
+
baseColumn: never;
|
|
2671
|
+
identity: undefined;
|
|
2672
|
+
generated: undefined;
|
|
2673
|
+
}, {}, {}>;
|
|
2674
|
+
tenantKind: drizzle_orm_pg_core.PgColumn<{
|
|
2675
|
+
name: "tenant_kind";
|
|
2676
|
+
tableName: "durable_schedules";
|
|
2677
|
+
dataType: "string";
|
|
2678
|
+
columnType: "PgText";
|
|
2679
|
+
data: string;
|
|
2680
|
+
driverParam: string;
|
|
2681
|
+
notNull: false;
|
|
2682
|
+
hasDefault: false;
|
|
2683
|
+
isPrimaryKey: false;
|
|
2684
|
+
isAutoincrement: false;
|
|
2685
|
+
hasRuntimeDefault: false;
|
|
2686
|
+
enumValues: [string, ...string[]];
|
|
2687
|
+
baseColumn: never;
|
|
2688
|
+
identity: undefined;
|
|
2689
|
+
generated: undefined;
|
|
2690
|
+
}, {}, {}>;
|
|
2555
2691
|
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
2556
2692
|
name: string;
|
|
2557
2693
|
tableName: "durable_schedules";
|
package/dist/pg/index.js
CHANGED
|
@@ -56,6 +56,8 @@ var DURABLE_PG_DDL = [
|
|
|
56
56
|
"priority" integer,
|
|
57
57
|
"namespace" text DEFAULT 'default' NOT NULL,
|
|
58
58
|
"origin" text,
|
|
59
|
+
"tenant_id" text,
|
|
60
|
+
"tenant_kind" text,
|
|
59
61
|
"created_at" timestamp with time zone NOT NULL,
|
|
60
62
|
"updated_at" timestamp with time zone NOT NULL
|
|
61
63
|
)`,
|
|
@@ -118,9 +120,16 @@ var DURABLE_PG_DDL = [
|
|
|
118
120
|
"tags" jsonb,
|
|
119
121
|
"spec" jsonb NOT NULL,
|
|
120
122
|
"state" jsonb NOT NULL,
|
|
123
|
+
"tenant_id" text,
|
|
124
|
+
"tenant_kind" text,
|
|
121
125
|
"created_at" timestamp with time zone NOT NULL,
|
|
122
126
|
"updated_at" timestamp with time zone NOT NULL
|
|
123
127
|
)`,
|
|
128
|
+
// Tenancy columns (the customer a run / schedule belongs to): added in place on an existing database.
|
|
129
|
+
`ALTER TABLE "durable_workflow_runs" ADD COLUMN IF NOT EXISTS "tenant_id" text`,
|
|
130
|
+
`ALTER TABLE "durable_workflow_runs" ADD COLUMN IF NOT EXISTS "tenant_kind" text`,
|
|
131
|
+
`ALTER TABLE "durable_schedules" ADD COLUMN IF NOT EXISTS "tenant_id" text`,
|
|
132
|
+
`ALTER TABLE "durable_schedules" ADD COLUMN IF NOT EXISTS "tenant_kind" text`,
|
|
124
133
|
`CREATE INDEX IF NOT EXISTS "durable_runs_status_idx" ON "durable_workflow_runs" USING btree ("status","wake_at")`,
|
|
125
134
|
`CREATE INDEX IF NOT EXISTS "durable_runs_workflow_status_idx" ON "durable_workflow_runs" USING btree ("workflow","status")`,
|
|
126
135
|
`CREATE INDEX IF NOT EXISTS "durable_workflow_runs_namespace_status_idx" ON "durable_workflow_runs" USING btree ("namespace","status","created_at")`,
|
|
@@ -133,6 +142,8 @@ var DURABLE_PG_DDL = [
|
|
|
133
142
|
`CREATE INDEX IF NOT EXISTS "durable_buffered_signals_token_idx" ON "durable_buffered_signals" USING btree ("token","id")`,
|
|
134
143
|
`CREATE INDEX IF NOT EXISTS "durable_buffered_events_name_published_at_idx" ON "durable_buffered_events" USING btree ("name","published_at")`,
|
|
135
144
|
`CREATE INDEX IF NOT EXISTS "durable_schedules_due_idx" ON "durable_schedules" USING btree ("paused","next_fire_at")`,
|
|
145
|
+
`CREATE INDEX IF NOT EXISTS "durable_workflow_runs_tenant_idx" ON "durable_workflow_runs" USING btree ("tenant_id","created_at")`,
|
|
146
|
+
`CREATE INDEX IF NOT EXISTS "durable_schedules_tenant_idx" ON "durable_schedules" USING btree ("tenant_id")`,
|
|
136
147
|
`CREATE INDEX IF NOT EXISTS "durable_signal_ids_expires_at_idx" ON "durable_signal_ids" USING btree ("expires_at")`
|
|
137
148
|
];
|
|
138
149
|
var SCHEMA_LOCK_KEY = "durable_schema";
|
|
@@ -208,6 +219,74 @@ __name(ensureDrizzlePgDurableSchema, "ensureDrizzlePgDurableSchema");
|
|
|
208
219
|
import { LIFECYCLE_REGISTRY_WORKFLOW, RUN_VALUE_FACET_SCAN, SINGLETON_ACTIVE_STATUSES, TERMINAL_RUN_STATUSES, attributePredicateOperands, axisIsRunColumn, clearTerminalSingletonAdmission, mergeRunFacetRows, mergeRunValueFacetRows, normalizeAttributeRows, parseDuration, retentionKeeps, runValueFacetsFromRuns, singletonAdmissionDenialPatch, singletonAdmissionTags } from "@dudousxd/nestjs-durable-core";
|
|
209
220
|
import { and, asc, desc, eq, exists, getTableColumns as getTableColumns2, getTableName as getTableName2, gt, gte, inArray, isNotNull, isNull, like, lt, lte, notInArray, or, sql as sql3 } from "drizzle-orm";
|
|
210
221
|
|
|
222
|
+
// src/tenant-columns.ts
|
|
223
|
+
var PG_STATEMENTS = [
|
|
224
|
+
'ALTER TABLE "durable_workflow_runs" ADD COLUMN IF NOT EXISTS "tenant_id" text;',
|
|
225
|
+
'ALTER TABLE "durable_workflow_runs" ADD COLUMN IF NOT EXISTS "tenant_kind" text;',
|
|
226
|
+
'ALTER TABLE "durable_schedules" ADD COLUMN IF NOT EXISTS "tenant_id" text;',
|
|
227
|
+
'ALTER TABLE "durable_schedules" ADD COLUMN IF NOT EXISTS "tenant_kind" text;',
|
|
228
|
+
'CREATE INDEX IF NOT EXISTS "durable_workflow_runs_tenant_idx" ON "durable_workflow_runs" USING btree ("tenant_id","created_at");',
|
|
229
|
+
'CREATE INDEX IF NOT EXISTS "durable_schedules_tenant_idx" ON "durable_schedules" USING btree ("tenant_id");'
|
|
230
|
+
];
|
|
231
|
+
var SQLITE_STATEMENTS = [
|
|
232
|
+
"ALTER TABLE durable_workflow_runs ADD COLUMN tenant_id TEXT;",
|
|
233
|
+
"ALTER TABLE durable_workflow_runs ADD COLUMN tenant_kind TEXT;",
|
|
234
|
+
"ALTER TABLE durable_schedules ADD COLUMN tenant_id TEXT;",
|
|
235
|
+
"ALTER TABLE durable_schedules ADD COLUMN tenant_kind TEXT;",
|
|
236
|
+
"CREATE INDEX IF NOT EXISTS durable_workflow_runs_tenant_idx ON durable_workflow_runs (tenant_id, created_at);",
|
|
237
|
+
"CREATE INDEX IF NOT EXISTS durable_schedules_tenant_idx ON durable_schedules (tenant_id);"
|
|
238
|
+
];
|
|
239
|
+
var TENANT_COLUMN = /tenant_(id|kind)/;
|
|
240
|
+
function isMissingTenantColumn(err) {
|
|
241
|
+
let cur = err;
|
|
242
|
+
for (let depth = 0; cur && depth < 5; depth += 1) {
|
|
243
|
+
const e = cur;
|
|
244
|
+
const message = typeof e.message === "string" ? e.message : "";
|
|
245
|
+
if (TENANT_COLUMN.test(message)) {
|
|
246
|
+
if (e.code === "42703" || /does not exist/.test(message) || /no such column/i.test(message)) {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
cur = e.cause;
|
|
251
|
+
}
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
__name(isMissingTenantColumn, "isMissingTenantColumn");
|
|
255
|
+
var MissingTenantColumnsError = class extends Error {
|
|
256
|
+
static {
|
|
257
|
+
__name(this, "MissingTenantColumnsError");
|
|
258
|
+
}
|
|
259
|
+
constructor(dialect, cause) {
|
|
260
|
+
const statements = dialect === "pg" ? PG_STATEMENTS : SQLITE_STATEMENTS;
|
|
261
|
+
const fix = dialect === "pg" ? "Generate a migration with drizzle-kit (`drizzle-kit generate`) from the store schema and apply it, or turn on the module's `autoSchema`, which adds them on boot." : "Generate a migration with drizzle-kit (`drizzle-kit generate`) from the store schema and apply it.";
|
|
262
|
+
super([
|
|
263
|
+
"[nestjs-durable] The durable tables are missing the tenancy columns (tenant_id, tenant_kind).",
|
|
264
|
+
"This version of the Drizzle store reads them on every run and schedule query, even with tenancy off.",
|
|
265
|
+
fix,
|
|
266
|
+
"The migration must contain:",
|
|
267
|
+
...statements.map((s) => ` ${s}`)
|
|
268
|
+
].join("\n"), {
|
|
269
|
+
cause
|
|
270
|
+
});
|
|
271
|
+
this.name = "MissingTenantColumnsError";
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
function tenantColumnsHint(dialect) {
|
|
275
|
+
return (err) => {
|
|
276
|
+
if (isMissingTenantColumn(err)) throw new MissingTenantColumnsError(dialect, err);
|
|
277
|
+
throw err;
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
__name(tenantColumnsHint, "tenantColumnsHint");
|
|
281
|
+
async function withTenantColumnsHint(dialect, query) {
|
|
282
|
+
try {
|
|
283
|
+
return await query;
|
|
284
|
+
} catch (err) {
|
|
285
|
+
return tenantColumnsHint(dialect)(err);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
__name(withTenantColumnsHint, "withTenantColumnsHint");
|
|
289
|
+
|
|
211
290
|
// src/pg/hot-path.ts
|
|
212
291
|
import * as drizzleOrm from "drizzle-orm";
|
|
213
292
|
import { getTableColumns } from "drizzle-orm";
|
|
@@ -351,9 +430,14 @@ var durableWorkflowRuns = pgTable("durable_workflow_runs", {
|
|
|
351
430
|
namespace: text("namespace").notNull().default(DEFAULT_NAMESPACE),
|
|
352
431
|
// Which package declared the workflow. Nullable, no default: NULL = unknown, never guessed.
|
|
353
432
|
origin: text("origin"),
|
|
433
|
+
// The customer (tenancy) the run belongs to — not the worker-pool `namespace`. NULL = none.
|
|
434
|
+
tenantId: text("tenant_id"),
|
|
435
|
+
tenantKind: text("tenant_kind"),
|
|
354
436
|
createdAt: tstz("created_at").notNull(),
|
|
355
437
|
updatedAt: tstz("updated_at").notNull()
|
|
356
438
|
}, (t) => [
|
|
439
|
+
// App-facing reads with tenancy on: `tenant_id = $1 ORDER BY created_at DESC`.
|
|
440
|
+
index("durable_workflow_runs_tenant_idx").on(t.tenantId, t.createdAt),
|
|
357
441
|
// Timer poller (`listDueTimers`) + recovery (`listIncompleteRuns`). Same name as the TypeORM DDL.
|
|
358
442
|
index("durable_runs_status_idx").on(t.status, t.wakeAt),
|
|
359
443
|
// Dashboard `listRuns({ workflow, status })` and the singleton gate's per-workflow scans.
|
|
@@ -475,12 +559,16 @@ var durableSchedules = pgTable(
|
|
|
475
559
|
tags: jsonb("tags").$type(),
|
|
476
560
|
spec: jsonb("spec").$type().notNull(),
|
|
477
561
|
state: jsonb("state").$type().notNull(),
|
|
562
|
+
// The customer the schedule (and every run it starts) belongs to. NULL = none.
|
|
563
|
+
tenantId: text("tenant_id"),
|
|
564
|
+
tenantKind: text("tenant_kind"),
|
|
478
565
|
createdAt: tstz("created_at").notNull(),
|
|
479
566
|
updatedAt: tstz("updated_at").notNull()
|
|
480
567
|
},
|
|
481
568
|
// The poll's "due by T" scan: `paused = false AND next_fire_at <= T ORDER BY next_fire_at`.
|
|
482
569
|
(t) => [
|
|
483
|
-
index("durable_schedules_due_idx").on(t.paused, t.nextFireAt)
|
|
570
|
+
index("durable_schedules_due_idx").on(t.paused, t.nextFireAt),
|
|
571
|
+
index("durable_schedules_tenant_idx").on(t.tenantId)
|
|
484
572
|
]
|
|
485
573
|
);
|
|
486
574
|
var durablePgSchema = {
|
|
@@ -507,6 +595,14 @@ function anyOf(conditions) {
|
|
|
507
595
|
return present.length ? or(...present) : sql3`1 = 0`;
|
|
508
596
|
}
|
|
509
597
|
__name(anyOf, "anyOf");
|
|
598
|
+
function tenantFilters(column, query) {
|
|
599
|
+
const one = /* @__PURE__ */ __name((id) => id === null ? isNull(column) : eq(column, id), "one");
|
|
600
|
+
return [
|
|
601
|
+
query.tenantId !== void 0 ? one(query.tenantId) : void 0,
|
|
602
|
+
query.tenantIds ? anyOf(query.tenantIds.map(one)) : void 0
|
|
603
|
+
];
|
|
604
|
+
}
|
|
605
|
+
__name(tenantFilters, "tenantFilters");
|
|
510
606
|
function namespaceFilter(namespace) {
|
|
511
607
|
if (namespace === void 0) return void 0;
|
|
512
608
|
if (namespace === DEFAULT_NAMESPACE || namespace === "") {
|
|
@@ -966,15 +1062,15 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
966
1062
|
}
|
|
967
1063
|
/** Crash recovery. Namespace-scoped: a worker re-drives only its own tenant's runs. */
|
|
968
1064
|
async listIncompleteRuns(namespace) {
|
|
969
|
-
const rows = await this.db.select().from(durableWorkflowRuns).where(and(inArray(durableWorkflowRuns.status, [
|
|
1065
|
+
const rows = await withTenantColumnsHint("pg", this.db.select().from(durableWorkflowRuns).where(and(inArray(durableWorkflowRuns.status, [
|
|
970
1066
|
"running",
|
|
971
1067
|
"cancelling"
|
|
972
|
-
]), namespaceFilter(namespace), this.scope()));
|
|
1068
|
+
]), namespaceFilter(namespace), this.scope())));
|
|
973
1069
|
return rows.map(fromRunRow);
|
|
974
1070
|
}
|
|
975
1071
|
async listOrphanedRuns(nowMs, limit, namespace, ownedBy) {
|
|
976
1072
|
if (limit <= 0) return [];
|
|
977
|
-
const
|
|
1073
|
+
const query = this.db.select().from(durableWorkflowRuns).where(and(inArray(durableWorkflowRuns.status, [
|
|
978
1074
|
"running",
|
|
979
1075
|
"cancelling"
|
|
980
1076
|
]), or(
|
|
@@ -983,12 +1079,13 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
983
1079
|
// A live lease left by a previous process with the caller's own instance id.
|
|
984
1080
|
ownedBy ? and(eq(durableWorkflowRuns.lockedBy, ownedBy.owner), lt(durableWorkflowRuns.lockedUntil, new Date(ownedBy.lockedBefore))) : void 0
|
|
985
1081
|
), namespaceFilter(namespace), this.scope())).orderBy(asc(durableWorkflowRuns.createdAt)).limit(limit);
|
|
1082
|
+
const rows = await withTenantColumnsHint("pg", query);
|
|
986
1083
|
return rows.map(fromRunRow);
|
|
987
1084
|
}
|
|
988
1085
|
/** FIFO pick-up, served by `durable_workflow_runs_namespace_status_idx`. The engine then leases
|
|
989
1086
|
* each run with {@link tryLockRun}; the listing itself takes no locks (it runs outside a tx). */
|
|
990
1087
|
async listPendingRuns(limit, namespace) {
|
|
991
|
-
const rows = await this.db.select().from(durableWorkflowRuns).where(and(eq(durableWorkflowRuns.status, "pending"), namespaceFilter(namespace), this.scope())).orderBy(asc(durableWorkflowRuns.createdAt)).limit(limit);
|
|
1088
|
+
const rows = await withTenantColumnsHint("pg", this.db.select().from(durableWorkflowRuns).where(and(eq(durableWorkflowRuns.status, "pending"), namespaceFilter(namespace), this.scope())).orderBy(asc(durableWorkflowRuns.createdAt)).limit(limit));
|
|
992
1089
|
return rows.map(fromRunRow);
|
|
993
1090
|
}
|
|
994
1091
|
async claimPendingRuns(limit, owner, leaseUntilMs, nowMs, namespace) {
|
|
@@ -999,7 +1096,7 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
999
1096
|
// A CTE, MATERIALIZED, picks the rows once. As a subquery in UPDATE ... FROM, Postgres may
|
|
1000
1097
|
// rescan it, and each rescan skips the rows this statement already updated and takes the
|
|
1001
1098
|
// next ones, so a claim of `limit` rows could lease every free pending run.
|
|
1002
|
-
await this.db.execute(sql3`WITH c AS MATERIALIZED (
|
|
1099
|
+
await withTenantColumnsHint("pg", this.db.execute(sql3`WITH c AS MATERIALIZED (
|
|
1003
1100
|
SELECT ${durableWorkflowRuns.id} AS claimed_id FROM ${durableWorkflowRuns}
|
|
1004
1101
|
WHERE ${filters}
|
|
1005
1102
|
ORDER BY ${durableWorkflowRuns.createdAt}, ${durableWorkflowRuns.id}
|
|
@@ -1011,13 +1108,13 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
1011
1108
|
${sql3.identifier(getTableColumns2(durableWorkflowRuns).lockedUntil.name)} = ${new Date(leaseUntilMs).toISOString()}::timestamptz
|
|
1012
1109
|
FROM c
|
|
1013
1110
|
WHERE r.${sql3.identifier(getTableColumns2(durableWorkflowRuns).id.name)} = c.claimed_id
|
|
1014
|
-
RETURNING ${returning}`)
|
|
1111
|
+
RETURNING ${returning}`))
|
|
1015
1112
|
);
|
|
1016
1113
|
return rows.map((raw) => fromRunRow(RUNS.decode(raw))).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime() || a.id.localeCompare(b.id));
|
|
1017
1114
|
}
|
|
1018
1115
|
async listDueTimers(nowMs, namespace, limit) {
|
|
1019
1116
|
const query = this.db.select().from(durableWorkflowRuns).where(and(eq(durableWorkflowRuns.status, "suspended"), isNotNull(durableWorkflowRuns.wakeAt), lte(durableWorkflowRuns.wakeAt, new Date(nowMs)), namespaceFilter(namespace), this.scope())).orderBy(asc(durableWorkflowRuns.wakeAt));
|
|
1020
|
-
const rows = limit !== void 0 ?
|
|
1117
|
+
const rows = await withTenantColumnsHint("pg", limit !== void 0 ? query.limit(limit) : query);
|
|
1021
1118
|
return rows.map(fromRunRow);
|
|
1022
1119
|
}
|
|
1023
1120
|
async tryLockRun(runId, owner, leaseUntilMs, nowMs) {
|
|
@@ -1084,6 +1181,8 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
1084
1181
|
// `null` selects the unattributed bucket; a value never matches a NULL origin.
|
|
1085
1182
|
query.origin === null ? isNull(durableWorkflowRuns.origin) : query.origin !== void 0 ? eq(durableWorkflowRuns.origin, query.origin) : void 0,
|
|
1086
1183
|
query.origins ? anyOf(query.origins.map((o) => o === null ? isNull(durableWorkflowRuns.origin) : eq(durableWorkflowRuns.origin, o))) : void 0,
|
|
1184
|
+
// The customer (tenancy matching rule): `null` = runs with no tenant.
|
|
1185
|
+
...tenantFilters(durableWorkflowRuns.tenantId, query),
|
|
1087
1186
|
query.status ? eq(durableWorkflowRuns.status, query.status) : void 0,
|
|
1088
1187
|
query.statuses ? query.statuses.length ? inArray(durableWorkflowRuns.status, query.statuses) : sql3`1 = 0` : void 0,
|
|
1089
1188
|
query.tag ? hasTag(query.tag) : void 0,
|
|
@@ -1180,10 +1279,10 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
1180
1279
|
async listSchedules(query) {
|
|
1181
1280
|
const base = this.db.select().from(durableSchedules).where(and(query.namespace !== void 0 ? eq(durableSchedules.namespace, query.namespace) : void 0, query.workflow !== void 0 ? eq(durableSchedules.workflow, query.workflow) : void 0, query.paused !== void 0 ? eq(durableSchedules.paused, query.paused) : void 0, query.tag !== void 0 ? sql3`${durableSchedules.tags} @> ${JSON.stringify([
|
|
1182
1281
|
query.tag
|
|
1183
|
-
])}::jsonb` : void 0, query.dueBy !== void 0 ? and(eq(durableSchedules.paused, false), lte(durableSchedules.nextFireAt, new Date(query.dueBy))) : void 0)).orderBy(sql3`${durableSchedules.nextFireAt} ASC NULLS LAST`, asc(durableSchedules.id)).$dynamic();
|
|
1282
|
+
])}::jsonb` : void 0, ...tenantFilters(durableSchedules.tenantId, query), query.dueBy !== void 0 ? and(eq(durableSchedules.paused, false), lte(durableSchedules.nextFireAt, new Date(query.dueBy))) : void 0)).orderBy(sql3`${durableSchedules.nextFireAt} ASC NULLS LAST`, asc(durableSchedules.id)).$dynamic();
|
|
1184
1283
|
if (query.limit != null) base.limit(query.limit);
|
|
1185
1284
|
if (query.offset != null) base.offset(query.offset);
|
|
1186
|
-
return (await base).map(fromScheduleRow);
|
|
1285
|
+
return (await withTenantColumnsHint("pg", base)).map(fromScheduleRow);
|
|
1187
1286
|
}
|
|
1188
1287
|
async listCheckpoints(runId) {
|
|
1189
1288
|
const rows = await this.db.select().from(durableStepCheckpoints).where(eq(durableStepCheckpoints.runId, runId)).orderBy(asc(durableStepCheckpoints.seq));
|
|
@@ -1725,6 +1824,8 @@ function toRunRow(run) {
|
|
|
1725
1824
|
priority: run.priority ?? null,
|
|
1726
1825
|
namespace: run.namespace || DEFAULT_NAMESPACE,
|
|
1727
1826
|
origin: run.origin ?? null,
|
|
1827
|
+
tenantId: run.tenantId ?? null,
|
|
1828
|
+
tenantKind: run.tenantKind ?? null,
|
|
1728
1829
|
createdAt: run.createdAt,
|
|
1729
1830
|
updatedAt: run.updatedAt
|
|
1730
1831
|
};
|
|
@@ -1748,6 +1849,8 @@ function toRunPatch(patch) {
|
|
|
1748
1849
|
if ("priority" in patch) row.priority = patch.priority ?? null;
|
|
1749
1850
|
if ("namespace" in patch) row.namespace = patch.namespace || DEFAULT_NAMESPACE;
|
|
1750
1851
|
if ("origin" in patch) row.origin = patch.origin ?? null;
|
|
1852
|
+
if ("tenantId" in patch) row.tenantId = patch.tenantId ?? null;
|
|
1853
|
+
if ("tenantKind" in patch) row.tenantKind = patch.tenantKind ?? null;
|
|
1751
1854
|
if (patch.createdAt != null) row.createdAt = patch.createdAt;
|
|
1752
1855
|
if (patch.updatedAt != null) row.updatedAt = patch.updatedAt;
|
|
1753
1856
|
return row;
|
|
@@ -1772,6 +1875,13 @@ function fromRunRow(row) {
|
|
|
1772
1875
|
priority: row.priority ?? void 0,
|
|
1773
1876
|
namespace: row.namespace || DEFAULT_NAMESPACE,
|
|
1774
1877
|
origin: row.origin ?? void 0,
|
|
1878
|
+
// NULL = no tenant; left off entirely so a tenancy-off run reads back unchanged.
|
|
1879
|
+
...row.tenantId != null ? {
|
|
1880
|
+
tenantId: row.tenantId
|
|
1881
|
+
} : {},
|
|
1882
|
+
...row.tenantKind != null ? {
|
|
1883
|
+
tenantKind: row.tenantKind
|
|
1884
|
+
} : {},
|
|
1775
1885
|
createdAt: row.createdAt,
|
|
1776
1886
|
updatedAt: row.updatedAt
|
|
1777
1887
|
};
|
|
@@ -1832,6 +1942,8 @@ function toScheduleRow(r) {
|
|
|
1832
1942
|
tags: r.tags ?? null,
|
|
1833
1943
|
spec: r.spec,
|
|
1834
1944
|
state: r.state,
|
|
1945
|
+
tenantId: r.tenantId ?? null,
|
|
1946
|
+
tenantKind: r.tenantKind ?? null,
|
|
1835
1947
|
createdAt: r.createdAt,
|
|
1836
1948
|
updatedAt: r.updatedAt
|
|
1837
1949
|
};
|
|
@@ -1846,6 +1958,8 @@ function toSchedulePatch(patch) {
|
|
|
1846
1958
|
if ("tags" in patch) set.tags = patch.tags ?? null;
|
|
1847
1959
|
if (patch.spec !== void 0) set.spec = patch.spec;
|
|
1848
1960
|
if (patch.state !== void 0) set.state = patch.state;
|
|
1961
|
+
if ("tenantId" in patch) set.tenantId = patch.tenantId ?? null;
|
|
1962
|
+
if ("tenantKind" in patch) set.tenantKind = patch.tenantKind ?? null;
|
|
1849
1963
|
if (patch.updatedAt !== void 0) set.updatedAt = patch.updatedAt;
|
|
1850
1964
|
return set;
|
|
1851
1965
|
}
|
|
@@ -1862,6 +1976,12 @@ function fromScheduleRow(row) {
|
|
|
1862
1976
|
} : {},
|
|
1863
1977
|
spec: row.spec ?? {},
|
|
1864
1978
|
state: row.state ?? {},
|
|
1979
|
+
...row.tenantId != null ? {
|
|
1980
|
+
tenantId: row.tenantId
|
|
1981
|
+
} : {},
|
|
1982
|
+
...row.tenantKind != null ? {
|
|
1983
|
+
tenantKind: row.tenantKind
|
|
1984
|
+
} : {},
|
|
1865
1985
|
createdAt: row.createdAt,
|
|
1866
1986
|
updatedAt: row.updatedAt
|
|
1867
1987
|
};
|