@tanstack/workflow-store-drizzle-postgres 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -4,6 +4,8 @@ Experimental Drizzle/Postgres durable execution store for TanStack Workflow.
4
4
 
5
5
  See the main [Persistence guide](../../docs/guide/persistence.md) and
6
6
  [Store adapters API](../../docs/api/store-adapters.md).
7
+ Maintainers changing the durable schema should follow
8
+ [SCHEMA_MIGRATIONS.md](./SCHEMA_MIGRATIONS.md).
7
9
 
8
10
  This adapter implements the `WorkflowExecutionStore` contract from
9
11
  `@tanstack/workflow-runtime`. Drizzle is only the database execution surface; the
@@ -21,6 +23,18 @@ import { createDrizzlePostgresWorkflowStore } from '@tanstack/workflow-store-dri
21
23
 
22
24
  const db = drizzle(pool)
23
25
  const store = createDrizzlePostgresWorkflowStore({ db })
26
+ ```
27
+
28
+ Apply the package-owned migration during setup/deploy:
24
29
 
25
- await store.ensureSchema()
30
+ ```bash
31
+ psql "$DATABASE_URL" -f node_modules/@tanstack/workflow-store-drizzle-postgres/migrations/0000_workflow_store.sql
26
32
  ```
33
+
34
+ `store.ensureSchema()` remains available for tests, local demos, and explicit
35
+ admin bootstrap scripts. Production deploys should prefer the published SQL
36
+ migration artifact so schema changes are reviewed and repeatable.
37
+
38
+ The migration creates `workflow_schema_migrations` and records the applied
39
+ Workflow store migration ID. Future schema changes will ship as additional
40
+ numbered SQL files in this package.
@@ -0,0 +1,85 @@
1
+ # Drizzle/Postgres Store Schema Migrations
2
+
3
+ `@tanstack/workflow-store-drizzle-postgres` owns the durable Workflow store
4
+ schema. Applications should apply package-owned migrations instead of copying
5
+ `workflow_*` tables into their own Drizzle schema.
6
+
7
+ ## When to Version
8
+
9
+ Create a changeset for this package whenever a change affects:
10
+
11
+ - SQL migration files in `migrations/`
12
+ - generated migration helpers in `src/migrations.ts`
13
+ - store schema statements in `src/schema-contract.ts`
14
+ - exported Drizzle table definitions in `src/tables.ts`
15
+ - runtime code that expects a different table, column, index, or lock shape
16
+
17
+ Use a patch changeset for backward-compatible additive schema changes. Use a
18
+ minor or major changeset when an upgrade requires coordinated application action
19
+ or cannot be safely rolled out with the previous runtime/store version.
20
+
21
+ ## Adding a Migration
22
+
23
+ 1. Add the next numbered SQL file under `migrations/`, for example
24
+ `0001_add_retention_indexes.sql`.
25
+ 2. Make the SQL idempotent where possible:
26
+ - use `create table if not exists`
27
+ - use `create index if not exists`
28
+ - prefer additive columns/indexes before destructive changes
29
+ 3. Insert a row into `workflow_schema_migrations` from the migration:
30
+
31
+ ```sql
32
+ insert into "workflow_schema_migrations" (
33
+ migration_id,
34
+ package_name,
35
+ package_version,
36
+ applied_at
37
+ )
38
+ values (
39
+ '0001_add_retention_indexes',
40
+ '@tanstack/workflow-store-drizzle-postgres',
41
+ null,
42
+ (extract(epoch from now()) * 1000)::bigint
43
+ )
44
+ on conflict (migration_id) do nothing;
45
+ ```
46
+
47
+ 4. Update `src/schema-contract.ts` so fresh installs get the same final schema.
48
+ 5. Update `src/migrations.ts` so programmatic migration helpers expose the new
49
+ migration in order.
50
+ 6. Update optional typed table exports in `src/tables.ts` if table definitions
51
+ changed.
52
+ 7. Update docs that mention production setup or compatibility.
53
+ 8. Add or update tests that verify:
54
+ - generated SQL matches the checked-in SQL artifact
55
+ - `ensureSchema()` creates the same final schema for local/test bootstrap
56
+ - the migration is recorded in `workflow_schema_migrations`
57
+
58
+ ## Compatibility Rules
59
+
60
+ - Runtime and host adapters assume the durable store schema already exists.
61
+ - Production deploys should apply package-owned SQL migrations before rolling
62
+ out a store adapter version that expects them.
63
+ - `ensureSchema()` is for tests, local demos, and explicit admin/bootstrap
64
+ scripts. Do not call it from request handlers, scheduled sweeps, or cron
65
+ ticks.
66
+ - Apps may import the optional Drizzle table definitions for diagnostics/admin
67
+ reads, but normal runtime use should not require app-owned `workflow_*` table
68
+ declarations.
69
+
70
+ ## Verification
71
+
72
+ Run these checks before handing off schema work:
73
+
74
+ ```bash
75
+ pnpm --filter @tanstack/workflow-store-drizzle-postgres test:lib
76
+ pnpm --filter @tanstack/workflow-store-drizzle-postgres test:types
77
+ pnpm --filter @tanstack/workflow-store-drizzle-postgres test:eslint
78
+ pnpm --filter @tanstack/workflow-store-drizzle-postgres build
79
+ pnpm --filter @tanstack/workflow-store-drizzle-postgres pack --dry-run
80
+ pnpm test:docs
81
+ pnpm test:knip
82
+ pnpm test:sherif
83
+ ```
84
+
85
+ Confirm the dry-run tarball includes every SQL file under `migrations/`.
package/dist/index.cjs CHANGED
@@ -1,5 +1,22 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_schema_contract = require('./schema-contract.cjs');
2
3
  const require_store = require('./store.cjs');
4
+ const require_migrations = require('./migrations.cjs');
5
+ const require_tables = require('./tables.cjs');
3
6
 
4
7
  exports.createDrizzlePostgresWorkflowStore = require_store.createDrizzlePostgresWorkflowStore;
5
- exports.defaultDrizzlePostgresWorkflowStoreTables = require_store.defaultDrizzlePostgresWorkflowStoreTables;
8
+ exports.defaultDrizzlePostgresWorkflowStoreTables = require_schema_contract.defaultDrizzlePostgresWorkflowStoreTables;
9
+ exports.drizzlePostgresWorkflowStoreSchemaVersion = require_migrations.drizzlePostgresWorkflowStoreSchemaVersion;
10
+ exports.getDrizzlePostgresWorkflowStoreMigrationSql = require_migrations.getDrizzlePostgresWorkflowStoreMigrationSql;
11
+ exports.getDrizzlePostgresWorkflowStoreMigrations = require_migrations.getDrizzlePostgresWorkflowStoreMigrations;
12
+ exports.getDrizzlePostgresWorkflowStoreSchemaStatements = require_schema_contract.getDrizzlePostgresWorkflowStoreSchemaStatements;
13
+ exports.resolveDrizzlePostgresWorkflowStoreTables = require_schema_contract.resolveDrizzlePostgresWorkflowStoreTables;
14
+ exports.workflowEventLocks = require_tables.workflowEventLocks;
15
+ exports.workflowEvents = require_tables.workflowEvents;
16
+ exports.workflowRunStates = require_tables.workflowRunStates;
17
+ exports.workflowRuns = require_tables.workflowRuns;
18
+ exports.workflowScheduleBuckets = require_tables.workflowScheduleBuckets;
19
+ exports.workflowSchedules = require_tables.workflowSchedules;
20
+ exports.workflowSchemaMigrations = require_tables.workflowSchemaMigrations;
21
+ exports.workflowSignalDeliveries = require_tables.workflowSignalDeliveries;
22
+ exports.workflowTimers = require_tables.workflowTimers;
package/dist/index.d.cts CHANGED
@@ -1,2 +1,5 @@
1
- import { DrizzlePostgresDatabase, DrizzlePostgresWorkflowStore, DrizzlePostgresWorkflowStoreOptions, DrizzlePostgresWorkflowStoreTables, createDrizzlePostgresWorkflowStore, defaultDrizzlePostgresWorkflowStoreTables } from "./store.cjs";
2
- export { type DrizzlePostgresDatabase, type DrizzlePostgresWorkflowStore, type DrizzlePostgresWorkflowStoreOptions, type DrizzlePostgresWorkflowStoreTables, createDrizzlePostgresWorkflowStore, defaultDrizzlePostgresWorkflowStoreTables };
1
+ import { DrizzlePostgresWorkflowStoreSchemaOptions, DrizzlePostgresWorkflowStoreTables, defaultDrizzlePostgresWorkflowStoreTables, getDrizzlePostgresWorkflowStoreSchemaStatements, resolveDrizzlePostgresWorkflowStoreTables } from "./schema-contract.cjs";
2
+ import { DrizzlePostgresDatabase, DrizzlePostgresWorkflowStore, DrizzlePostgresWorkflowStoreOptions, createDrizzlePostgresWorkflowStore } from "./store.cjs";
3
+ import { DrizzlePostgresWorkflowStoreMigration, drizzlePostgresWorkflowStoreSchemaVersion, getDrizzlePostgresWorkflowStoreMigrationSql, getDrizzlePostgresWorkflowStoreMigrations } from "./migrations.cjs";
4
+ import { workflowEventLocks, workflowEvents, workflowRunStates, workflowRuns, workflowScheduleBuckets, workflowSchedules, workflowSchemaMigrations, workflowSignalDeliveries, workflowTimers } from "./tables.cjs";
5
+ export { type DrizzlePostgresDatabase, type DrizzlePostgresWorkflowStore, type DrizzlePostgresWorkflowStoreMigration, type DrizzlePostgresWorkflowStoreOptions, type DrizzlePostgresWorkflowStoreSchemaOptions, type DrizzlePostgresWorkflowStoreTables, createDrizzlePostgresWorkflowStore, defaultDrizzlePostgresWorkflowStoreTables, drizzlePostgresWorkflowStoreSchemaVersion, getDrizzlePostgresWorkflowStoreMigrationSql, getDrizzlePostgresWorkflowStoreMigrations, getDrizzlePostgresWorkflowStoreSchemaStatements, resolveDrizzlePostgresWorkflowStoreTables, workflowEventLocks, workflowEvents, workflowRunStates, workflowRuns, workflowScheduleBuckets, workflowSchedules, workflowSchemaMigrations, workflowSignalDeliveries, workflowTimers };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- import { DrizzlePostgresDatabase, DrizzlePostgresWorkflowStore, DrizzlePostgresWorkflowStoreOptions, DrizzlePostgresWorkflowStoreTables, createDrizzlePostgresWorkflowStore, defaultDrizzlePostgresWorkflowStoreTables } from "./store.js";
2
- export { type DrizzlePostgresDatabase, type DrizzlePostgresWorkflowStore, type DrizzlePostgresWorkflowStoreOptions, type DrizzlePostgresWorkflowStoreTables, createDrizzlePostgresWorkflowStore, defaultDrizzlePostgresWorkflowStoreTables };
1
+ import { DrizzlePostgresWorkflowStoreSchemaOptions, DrizzlePostgresWorkflowStoreTables, defaultDrizzlePostgresWorkflowStoreTables, getDrizzlePostgresWorkflowStoreSchemaStatements, resolveDrizzlePostgresWorkflowStoreTables } from "./schema-contract.js";
2
+ import { DrizzlePostgresDatabase, DrizzlePostgresWorkflowStore, DrizzlePostgresWorkflowStoreOptions, createDrizzlePostgresWorkflowStore } from "./store.js";
3
+ import { DrizzlePostgresWorkflowStoreMigration, drizzlePostgresWorkflowStoreSchemaVersion, getDrizzlePostgresWorkflowStoreMigrationSql, getDrizzlePostgresWorkflowStoreMigrations } from "./migrations.js";
4
+ import { workflowEventLocks, workflowEvents, workflowRunStates, workflowRuns, workflowScheduleBuckets, workflowSchedules, workflowSchemaMigrations, workflowSignalDeliveries, workflowTimers } from "./tables.js";
5
+ export { type DrizzlePostgresDatabase, type DrizzlePostgresWorkflowStore, type DrizzlePostgresWorkflowStoreMigration, type DrizzlePostgresWorkflowStoreOptions, type DrizzlePostgresWorkflowStoreSchemaOptions, type DrizzlePostgresWorkflowStoreTables, createDrizzlePostgresWorkflowStore, defaultDrizzlePostgresWorkflowStoreTables, drizzlePostgresWorkflowStoreSchemaVersion, getDrizzlePostgresWorkflowStoreMigrationSql, getDrizzlePostgresWorkflowStoreMigrations, getDrizzlePostgresWorkflowStoreSchemaStatements, resolveDrizzlePostgresWorkflowStoreTables, workflowEventLocks, workflowEvents, workflowRunStates, workflowRuns, workflowScheduleBuckets, workflowSchedules, workflowSchemaMigrations, workflowSignalDeliveries, workflowTimers };
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
- import { createDrizzlePostgresWorkflowStore, defaultDrizzlePostgresWorkflowStoreTables } from "./store.js";
1
+ import { defaultDrizzlePostgresWorkflowStoreTables, getDrizzlePostgresWorkflowStoreSchemaStatements, resolveDrizzlePostgresWorkflowStoreTables } from "./schema-contract.js";
2
+ import { createDrizzlePostgresWorkflowStore } from "./store.js";
3
+ import { drizzlePostgresWorkflowStoreSchemaVersion, getDrizzlePostgresWorkflowStoreMigrationSql, getDrizzlePostgresWorkflowStoreMigrations } from "./migrations.js";
4
+ import { workflowEventLocks, workflowEvents, workflowRunStates, workflowRuns, workflowScheduleBuckets, workflowSchedules, workflowSchemaMigrations, workflowSignalDeliveries, workflowTimers } from "./tables.js";
2
5
 
3
- export { createDrizzlePostgresWorkflowStore, defaultDrizzlePostgresWorkflowStoreTables };
6
+ export { createDrizzlePostgresWorkflowStore, defaultDrizzlePostgresWorkflowStoreTables, drizzlePostgresWorkflowStoreSchemaVersion, getDrizzlePostgresWorkflowStoreMigrationSql, getDrizzlePostgresWorkflowStoreMigrations, getDrizzlePostgresWorkflowStoreSchemaStatements, resolveDrizzlePostgresWorkflowStoreTables, workflowEventLocks, workflowEvents, workflowRunStates, workflowRuns, workflowScheduleBuckets, workflowSchedules, workflowSchemaMigrations, workflowSignalDeliveries, workflowTimers };
@@ -0,0 +1,23 @@
1
+ const require_schema_contract = require('./schema-contract.cjs');
2
+
3
+ //#region src/migrations.ts
4
+ const drizzlePostgresWorkflowStoreSchemaVersion = "0000_workflow_store";
5
+ function getDrizzlePostgresWorkflowStoreMigrations(options) {
6
+ const statements = require_schema_contract.getDrizzlePostgresWorkflowStoreSchemaStatements(options);
7
+ return [{
8
+ id: "0000_workflow_store",
9
+ name: "Create TanStack Workflow Drizzle/Postgres store tables",
10
+ order: 0,
11
+ statements,
12
+ sql: `${statements.join(";\n\n")};\n`
13
+ }];
14
+ }
15
+ function getDrizzlePostgresWorkflowStoreMigrationSql(options) {
16
+ return getDrizzlePostgresWorkflowStoreMigrations(options)[0].sql;
17
+ }
18
+
19
+ //#endregion
20
+ exports.drizzlePostgresWorkflowStoreSchemaVersion = drizzlePostgresWorkflowStoreSchemaVersion;
21
+ exports.getDrizzlePostgresWorkflowStoreMigrationSql = getDrizzlePostgresWorkflowStoreMigrationSql;
22
+ exports.getDrizzlePostgresWorkflowStoreMigrations = getDrizzlePostgresWorkflowStoreMigrations;
23
+ //# sourceMappingURL=migrations.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.cjs","names":["getDrizzlePostgresWorkflowStoreSchemaStatements"],"sources":["../src/migrations.ts"],"sourcesContent":["import { getDrizzlePostgresWorkflowStoreSchemaStatements } from './schema-contract'\nimport type { DrizzlePostgresWorkflowStoreSchemaOptions } from './schema-contract'\n\nexport interface DrizzlePostgresWorkflowStoreMigration {\n id: string\n name: string\n order: number\n statements: Array<string>\n sql: string\n}\n\nexport const drizzlePostgresWorkflowStoreSchemaVersion = '0000_workflow_store'\n\nexport function getDrizzlePostgresWorkflowStoreMigrations(\n options?: DrizzlePostgresWorkflowStoreSchemaOptions,\n): Array<DrizzlePostgresWorkflowStoreMigration> {\n const statements = getDrizzlePostgresWorkflowStoreSchemaStatements(options)\n\n return [\n {\n id: '0000_workflow_store',\n name: 'Create TanStack Workflow Drizzle/Postgres store tables',\n order: 0,\n statements,\n sql: `${statements.join(';\\n\\n')};\\n`,\n },\n ]\n}\n\nexport function getDrizzlePostgresWorkflowStoreMigrationSql(\n options?: DrizzlePostgresWorkflowStoreSchemaOptions,\n): string {\n return getDrizzlePostgresWorkflowStoreMigrations(options)[0]!.sql\n}\n"],"mappings":";;;AAWA,MAAa,4CAA4C;AAEzD,SAAgB,0CACd,SAC8C;CAC9C,MAAM,aAAaA,wEAAgD,QAAQ;AAE3E,QAAO,CACL;EACE,IAAI;EACJ,MAAM;EACN,OAAO;EACP;EACA,KAAK,GAAG,WAAW,KAAK,QAAQ,CAAC;EAClC,CACF;;AAGH,SAAgB,4CACd,SACQ;AACR,QAAO,0CAA0C,QAAQ,CAAC,GAAI"}
@@ -0,0 +1,16 @@
1
+ import { DrizzlePostgresWorkflowStoreSchemaOptions } from "./schema-contract.cjs";
2
+
3
+ //#region src/migrations.d.ts
4
+ interface DrizzlePostgresWorkflowStoreMigration {
5
+ id: string;
6
+ name: string;
7
+ order: number;
8
+ statements: Array<string>;
9
+ sql: string;
10
+ }
11
+ declare const drizzlePostgresWorkflowStoreSchemaVersion = "0000_workflow_store";
12
+ declare function getDrizzlePostgresWorkflowStoreMigrations(options?: DrizzlePostgresWorkflowStoreSchemaOptions): Array<DrizzlePostgresWorkflowStoreMigration>;
13
+ declare function getDrizzlePostgresWorkflowStoreMigrationSql(options?: DrizzlePostgresWorkflowStoreSchemaOptions): string;
14
+ //#endregion
15
+ export { DrizzlePostgresWorkflowStoreMigration, drizzlePostgresWorkflowStoreSchemaVersion, getDrizzlePostgresWorkflowStoreMigrationSql, getDrizzlePostgresWorkflowStoreMigrations };
16
+ //# sourceMappingURL=migrations.d.cts.map
@@ -0,0 +1,16 @@
1
+ import { DrizzlePostgresWorkflowStoreSchemaOptions } from "./schema-contract.js";
2
+
3
+ //#region src/migrations.d.ts
4
+ interface DrizzlePostgresWorkflowStoreMigration {
5
+ id: string;
6
+ name: string;
7
+ order: number;
8
+ statements: Array<string>;
9
+ sql: string;
10
+ }
11
+ declare const drizzlePostgresWorkflowStoreSchemaVersion = "0000_workflow_store";
12
+ declare function getDrizzlePostgresWorkflowStoreMigrations(options?: DrizzlePostgresWorkflowStoreSchemaOptions): Array<DrizzlePostgresWorkflowStoreMigration>;
13
+ declare function getDrizzlePostgresWorkflowStoreMigrationSql(options?: DrizzlePostgresWorkflowStoreSchemaOptions): string;
14
+ //#endregion
15
+ export { DrizzlePostgresWorkflowStoreMigration, drizzlePostgresWorkflowStoreSchemaVersion, getDrizzlePostgresWorkflowStoreMigrationSql, getDrizzlePostgresWorkflowStoreMigrations };
16
+ //# sourceMappingURL=migrations.d.ts.map
@@ -0,0 +1,21 @@
1
+ import { getDrizzlePostgresWorkflowStoreSchemaStatements } from "./schema-contract.js";
2
+
3
+ //#region src/migrations.ts
4
+ const drizzlePostgresWorkflowStoreSchemaVersion = "0000_workflow_store";
5
+ function getDrizzlePostgresWorkflowStoreMigrations(options) {
6
+ const statements = getDrizzlePostgresWorkflowStoreSchemaStatements(options);
7
+ return [{
8
+ id: "0000_workflow_store",
9
+ name: "Create TanStack Workflow Drizzle/Postgres store tables",
10
+ order: 0,
11
+ statements,
12
+ sql: `${statements.join(";\n\n")};\n`
13
+ }];
14
+ }
15
+ function getDrizzlePostgresWorkflowStoreMigrationSql(options) {
16
+ return getDrizzlePostgresWorkflowStoreMigrations(options)[0].sql;
17
+ }
18
+
19
+ //#endregion
20
+ export { drizzlePostgresWorkflowStoreSchemaVersion, getDrizzlePostgresWorkflowStoreMigrationSql, getDrizzlePostgresWorkflowStoreMigrations };
21
+ //# sourceMappingURL=migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.js","names":[],"sources":["../src/migrations.ts"],"sourcesContent":["import { getDrizzlePostgresWorkflowStoreSchemaStatements } from './schema-contract'\nimport type { DrizzlePostgresWorkflowStoreSchemaOptions } from './schema-contract'\n\nexport interface DrizzlePostgresWorkflowStoreMigration {\n id: string\n name: string\n order: number\n statements: Array<string>\n sql: string\n}\n\nexport const drizzlePostgresWorkflowStoreSchemaVersion = '0000_workflow_store'\n\nexport function getDrizzlePostgresWorkflowStoreMigrations(\n options?: DrizzlePostgresWorkflowStoreSchemaOptions,\n): Array<DrizzlePostgresWorkflowStoreMigration> {\n const statements = getDrizzlePostgresWorkflowStoreSchemaStatements(options)\n\n return [\n {\n id: '0000_workflow_store',\n name: 'Create TanStack Workflow Drizzle/Postgres store tables',\n order: 0,\n statements,\n sql: `${statements.join(';\\n\\n')};\\n`,\n },\n ]\n}\n\nexport function getDrizzlePostgresWorkflowStoreMigrationSql(\n options?: DrizzlePostgresWorkflowStoreSchemaOptions,\n): string {\n return getDrizzlePostgresWorkflowStoreMigrations(options)[0]!.sql\n}\n"],"mappings":";;;AAWA,MAAa,4CAA4C;AAEzD,SAAgB,0CACd,SAC8C;CAC9C,MAAM,aAAa,gDAAgD,QAAQ;AAE3E,QAAO,CACL;EACE,IAAI;EACJ,MAAM;EACN,OAAO;EACP;EACA,KAAK,GAAG,WAAW,KAAK,QAAQ,CAAC;EAClC,CACF;;AAGH,SAAgB,4CACd,SACQ;AACR,QAAO,0CAA0C,QAAQ,CAAC,GAAI"}
@@ -0,0 +1,169 @@
1
+
2
+ //#region src/schema-contract.ts
3
+ const defaultDrizzlePostgresWorkflowStoreTables = {
4
+ schemaMigrations: "workflow_schema_migrations",
5
+ runs: "workflow_runs",
6
+ runStates: "workflow_run_states",
7
+ eventLocks: "workflow_event_locks",
8
+ events: "workflow_events",
9
+ timers: "workflow_timers",
10
+ signalDeliveries: "workflow_signal_deliveries",
11
+ schedules: "workflow_schedules",
12
+ scheduleBuckets: "workflow_schedule_buckets"
13
+ };
14
+ function resolveDrizzlePostgresWorkflowStoreTables(tables) {
15
+ return {
16
+ ...defaultDrizzlePostgresWorkflowStoreTables,
17
+ ...tables
18
+ };
19
+ }
20
+ function getDrizzlePostgresWorkflowStoreSchemaStatements(options = {}) {
21
+ const tables = resolveDrizzlePostgresWorkflowStoreTables(options.tables);
22
+ const schemaMigrations = qualifiedTableName(options.schema, tables.schemaMigrations);
23
+ const runs = qualifiedTableName(options.schema, tables.runs);
24
+ const runStates = qualifiedTableName(options.schema, tables.runStates);
25
+ const eventLocks = qualifiedTableName(options.schema, tables.eventLocks);
26
+ const events = qualifiedTableName(options.schema, tables.events);
27
+ const timers = qualifiedTableName(options.schema, tables.timers);
28
+ const signalDeliveries = qualifiedTableName(options.schema, tables.signalDeliveries);
29
+ const schedules = qualifiedTableName(options.schema, tables.schedules);
30
+ const scheduleBuckets = qualifiedTableName(options.schema, tables.scheduleBuckets);
31
+ return [
32
+ ...options.schema ? [`create schema if not exists ${quoteIdent(options.schema)}`] : [],
33
+ `create table if not exists ${schemaMigrations} (
34
+ migration_id text primary key,
35
+ package_name text not null,
36
+ package_version text,
37
+ applied_at bigint not null
38
+ )`,
39
+ `create table if not exists ${runs} (
40
+ run_id text primary key,
41
+ workflow_id text not null,
42
+ workflow_version text,
43
+ status text not null,
44
+ input jsonb not null,
45
+ output jsonb,
46
+ error jsonb,
47
+ awaiting jsonb,
48
+ waiting_for jsonb,
49
+ pending_approval jsonb,
50
+ wake_at bigint,
51
+ lease_owner text,
52
+ lease_expires_at bigint,
53
+ created_at bigint not null,
54
+ updated_at bigint not null
55
+ )`,
56
+ `alter table ${runs} add column if not exists awaiting jsonb`,
57
+ `create index if not exists ${quoteIdent(`${tables.runs}_status_idx`)}
58
+ on ${runs} (status, updated_at)`,
59
+ `create index if not exists ${quoteIdent(`${tables.runs}_lease_idx`)}
60
+ on ${runs} (status, lease_expires_at)`,
61
+ `create table if not exists ${runStates} (
62
+ run_id text primary key,
63
+ workflow_id text not null,
64
+ workflow_version text,
65
+ status text not null,
66
+ input jsonb not null,
67
+ output jsonb,
68
+ error jsonb,
69
+ awaiting jsonb,
70
+ waiting_for jsonb,
71
+ pending_approval jsonb,
72
+ created_at bigint not null,
73
+ updated_at bigint not null
74
+ )`,
75
+ `alter table ${runStates} add column if not exists awaiting jsonb`,
76
+ `create table if not exists ${eventLocks} (
77
+ run_id text primary key,
78
+ created_at bigint not null
79
+ )`,
80
+ `create table if not exists ${events} (
81
+ run_id text not null,
82
+ event_index integer not null,
83
+ event_type text not null,
84
+ step_id text,
85
+ event jsonb not null,
86
+ created_at bigint not null,
87
+ primary key (run_id, event_index)
88
+ )`,
89
+ `create index if not exists ${quoteIdent(`${tables.events}_type_idx`)}
90
+ on ${events} (run_id, event_type)`,
91
+ `create table if not exists ${timers} (
92
+ run_id text not null,
93
+ signal_id text not null,
94
+ workflow_id text not null,
95
+ workflow_version text,
96
+ wake_at bigint not null,
97
+ lease_owner text,
98
+ lease_expires_at bigint,
99
+ primary key (run_id, signal_id)
100
+ )`,
101
+ `create index if not exists ${quoteIdent(`${tables.timers}_due_idx`)}
102
+ on ${timers} (wake_at, lease_expires_at)`,
103
+ `create table if not exists ${signalDeliveries} (
104
+ run_id text not null,
105
+ signal_id text not null,
106
+ created_at bigint not null,
107
+ primary key (run_id, signal_id)
108
+ )`,
109
+ `create table if not exists ${schedules} (
110
+ schedule_id text primary key,
111
+ workflow_id text not null,
112
+ workflow_version text,
113
+ schedule jsonb not null,
114
+ overlap_policy text not null,
115
+ input jsonb,
116
+ next_fire_at bigint,
117
+ enabled boolean not null,
118
+ updated_at bigint not null
119
+ )`,
120
+ `create index if not exists ${quoteIdent(`${tables.schedules}_due_idx`)}
121
+ on ${schedules} (enabled, next_fire_at)`,
122
+ `create table if not exists ${scheduleBuckets} (
123
+ schedule_id text not null,
124
+ bucket_id text not null,
125
+ workflow_id text not null,
126
+ workflow_version text,
127
+ run_id text not null,
128
+ fire_at bigint not null,
129
+ input jsonb,
130
+ overlap_policy text not null,
131
+ status text not null,
132
+ lease_owner text,
133
+ lease_expires_at bigint,
134
+ started_at bigint,
135
+ primary key (schedule_id, bucket_id)
136
+ )`,
137
+ `create index if not exists ${quoteIdent(`${tables.scheduleBuckets}_lease_idx`)}
138
+ on ${scheduleBuckets} (status, fire_at, lease_expires_at)`,
139
+ `insert into ${schemaMigrations} (
140
+ migration_id,
141
+ package_name,
142
+ package_version,
143
+ applied_at
144
+ )
145
+ values (
146
+ '0000_workflow_store',
147
+ '@tanstack/workflow-store-drizzle-postgres',
148
+ null,
149
+ (extract(epoch from now()) * 1000)::bigint
150
+ )
151
+ on conflict (migration_id) do nothing`
152
+ ].map(normalizeSqlStatement);
153
+ }
154
+ function qualifiedTableName(schema, table) {
155
+ return schema ? `${quoteIdent(schema)}.${quoteIdent(table)}` : quoteIdent(table);
156
+ }
157
+ function quoteIdent(identifier) {
158
+ return `"${identifier.replaceAll("\"", "\"\"")}"`;
159
+ }
160
+ function normalizeSqlStatement(statement) {
161
+ return statement.split("\n").map((line, index) => index === 0 ? line.trimEnd() : line.replace(/^ {4}/, "").trimEnd()).join("\n");
162
+ }
163
+
164
+ //#endregion
165
+ exports.defaultDrizzlePostgresWorkflowStoreTables = defaultDrizzlePostgresWorkflowStoreTables;
166
+ exports.getDrizzlePostgresWorkflowStoreSchemaStatements = getDrizzlePostgresWorkflowStoreSchemaStatements;
167
+ exports.qualifiedTableName = qualifiedTableName;
168
+ exports.resolveDrizzlePostgresWorkflowStoreTables = resolveDrizzlePostgresWorkflowStoreTables;
169
+ //# sourceMappingURL=schema-contract.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-contract.cjs","names":[],"sources":["../src/schema-contract.ts"],"sourcesContent":["export interface DrizzlePostgresWorkflowStoreTables {\n schemaMigrations: string\n runs: string\n runStates: string\n eventLocks: string\n events: string\n timers: string\n signalDeliveries: string\n schedules: string\n scheduleBuckets: string\n}\n\nexport interface DrizzlePostgresWorkflowStoreSchemaOptions {\n schema?: string\n tables?: Partial<DrizzlePostgresWorkflowStoreTables>\n}\n\nexport const defaultDrizzlePostgresWorkflowStoreTables: DrizzlePostgresWorkflowStoreTables =\n {\n schemaMigrations: 'workflow_schema_migrations',\n runs: 'workflow_runs',\n runStates: 'workflow_run_states',\n eventLocks: 'workflow_event_locks',\n events: 'workflow_events',\n timers: 'workflow_timers',\n signalDeliveries: 'workflow_signal_deliveries',\n schedules: 'workflow_schedules',\n scheduleBuckets: 'workflow_schedule_buckets',\n }\n\nexport function resolveDrizzlePostgresWorkflowStoreTables(\n tables?: Partial<DrizzlePostgresWorkflowStoreTables>,\n): DrizzlePostgresWorkflowStoreTables {\n return {\n ...defaultDrizzlePostgresWorkflowStoreTables,\n ...tables,\n }\n}\n\nexport function getDrizzlePostgresWorkflowStoreSchemaStatements(\n options: DrizzlePostgresWorkflowStoreSchemaOptions = {},\n): Array<string> {\n const tables = resolveDrizzlePostgresWorkflowStoreTables(options.tables)\n const schemaMigrations = qualifiedTableName(\n options.schema,\n tables.schemaMigrations,\n )\n const runs = qualifiedTableName(options.schema, tables.runs)\n const runStates = qualifiedTableName(options.schema, tables.runStates)\n const eventLocks = qualifiedTableName(options.schema, tables.eventLocks)\n const events = qualifiedTableName(options.schema, tables.events)\n const timers = qualifiedTableName(options.schema, tables.timers)\n const signalDeliveries = qualifiedTableName(\n options.schema,\n tables.signalDeliveries,\n )\n const schedules = qualifiedTableName(options.schema, tables.schedules)\n const scheduleBuckets = qualifiedTableName(\n options.schema,\n tables.scheduleBuckets,\n )\n\n return [\n ...(options.schema\n ? [`create schema if not exists ${quoteIdent(options.schema)}`]\n : []),\n `create table if not exists ${schemaMigrations} (\n migration_id text primary key,\n package_name text not null,\n package_version text,\n applied_at bigint not null\n )`,\n `create table if not exists ${runs} (\n run_id text primary key,\n workflow_id text not null,\n workflow_version text,\n status text not null,\n input jsonb not null,\n output jsonb,\n error jsonb,\n awaiting jsonb,\n waiting_for jsonb,\n pending_approval jsonb,\n wake_at bigint,\n lease_owner text,\n lease_expires_at bigint,\n created_at bigint not null,\n updated_at bigint not null\n )`,\n `alter table ${runs} add column if not exists awaiting jsonb`,\n `create index if not exists ${quoteIdent(`${tables.runs}_status_idx`)}\n on ${runs} (status, updated_at)`,\n `create index if not exists ${quoteIdent(`${tables.runs}_lease_idx`)}\n on ${runs} (status, lease_expires_at)`,\n `create table if not exists ${runStates} (\n run_id text primary key,\n workflow_id text not null,\n workflow_version text,\n status text not null,\n input jsonb not null,\n output jsonb,\n error jsonb,\n awaiting jsonb,\n waiting_for jsonb,\n pending_approval jsonb,\n created_at bigint not null,\n updated_at bigint not null\n )`,\n `alter table ${runStates} add column if not exists awaiting jsonb`,\n `create table if not exists ${eventLocks} (\n run_id text primary key,\n created_at bigint not null\n )`,\n `create table if not exists ${events} (\n run_id text not null,\n event_index integer not null,\n event_type text not null,\n step_id text,\n event jsonb not null,\n created_at bigint not null,\n primary key (run_id, event_index)\n )`,\n `create index if not exists ${quoteIdent(`${tables.events}_type_idx`)}\n on ${events} (run_id, event_type)`,\n `create table if not exists ${timers} (\n run_id text not null,\n signal_id text not null,\n workflow_id text not null,\n workflow_version text,\n wake_at bigint not null,\n lease_owner text,\n lease_expires_at bigint,\n primary key (run_id, signal_id)\n )`,\n `create index if not exists ${quoteIdent(`${tables.timers}_due_idx`)}\n on ${timers} (wake_at, lease_expires_at)`,\n `create table if not exists ${signalDeliveries} (\n run_id text not null,\n signal_id text not null,\n created_at bigint not null,\n primary key (run_id, signal_id)\n )`,\n `create table if not exists ${schedules} (\n schedule_id text primary key,\n workflow_id text not null,\n workflow_version text,\n schedule jsonb not null,\n overlap_policy text not null,\n input jsonb,\n next_fire_at bigint,\n enabled boolean not null,\n updated_at bigint not null\n )`,\n `create index if not exists ${quoteIdent(`${tables.schedules}_due_idx`)}\n on ${schedules} (enabled, next_fire_at)`,\n `create table if not exists ${scheduleBuckets} (\n schedule_id text not null,\n bucket_id text not null,\n workflow_id text not null,\n workflow_version text,\n run_id text not null,\n fire_at bigint not null,\n input jsonb,\n overlap_policy text not null,\n status text not null,\n lease_owner text,\n lease_expires_at bigint,\n started_at bigint,\n primary key (schedule_id, bucket_id)\n )`,\n `create index if not exists ${quoteIdent(\n `${tables.scheduleBuckets}_lease_idx`,\n )}\n on ${scheduleBuckets} (status, fire_at, lease_expires_at)`,\n `insert into ${schemaMigrations} (\n migration_id,\n package_name,\n package_version,\n applied_at\n )\n values (\n '0000_workflow_store',\n '@tanstack/workflow-store-drizzle-postgres',\n null,\n (extract(epoch from now()) * 1000)::bigint\n )\n on conflict (migration_id) do nothing`,\n ].map(normalizeSqlStatement)\n}\n\nexport function qualifiedTableName(schema: string | undefined, table: string) {\n return schema\n ? `${quoteIdent(schema)}.${quoteIdent(table)}`\n : quoteIdent(table)\n}\n\nfunction quoteIdent(identifier: string) {\n return `\"${identifier.replaceAll('\"', '\"\"')}\"`\n}\n\nfunction normalizeSqlStatement(statement: string) {\n return statement\n .split('\\n')\n .map((line, index) =>\n index === 0 ? line.trimEnd() : line.replace(/^ {4}/, '').trimEnd(),\n )\n .join('\\n')\n}\n"],"mappings":";;AAiBA,MAAa,4CACX;CACE,kBAAkB;CAClB,MAAM;CACN,WAAW;CACX,YAAY;CACZ,QAAQ;CACR,QAAQ;CACR,kBAAkB;CAClB,WAAW;CACX,iBAAiB;CAClB;AAEH,SAAgB,0CACd,QACoC;AACpC,QAAO;EACL,GAAG;EACH,GAAG;EACJ;;AAGH,SAAgB,gDACd,UAAqD,EAAE,EACxC;CACf,MAAM,SAAS,0CAA0C,QAAQ,OAAO;CACxE,MAAM,mBAAmB,mBACvB,QAAQ,QACR,OAAO,iBACR;CACD,MAAM,OAAO,mBAAmB,QAAQ,QAAQ,OAAO,KAAK;CAC5D,MAAM,YAAY,mBAAmB,QAAQ,QAAQ,OAAO,UAAU;CACtE,MAAM,aAAa,mBAAmB,QAAQ,QAAQ,OAAO,WAAW;CACxE,MAAM,SAAS,mBAAmB,QAAQ,QAAQ,OAAO,OAAO;CAChE,MAAM,SAAS,mBAAmB,QAAQ,QAAQ,OAAO,OAAO;CAChE,MAAM,mBAAmB,mBACvB,QAAQ,QACR,OAAO,iBACR;CACD,MAAM,YAAY,mBAAmB,QAAQ,QAAQ,OAAO,UAAU;CACtE,MAAM,kBAAkB,mBACtB,QAAQ,QACR,OAAO,gBACR;AAED,QAAO;EACL,GAAI,QAAQ,SACR,CAAC,+BAA+B,WAAW,QAAQ,OAAO,GAAG,GAC7D,EAAE;EACN,8BAA8B,iBAAiB;;;;;;EAM/C,8BAA8B,KAAK;;;;;;;;;;;;;;;;;EAiBnC,eAAe,KAAK;EACpB,8BAA8B,WAAW,GAAG,OAAO,KAAK,aAAa,CAAC;WAC/D,KAAK;EACZ,8BAA8B,WAAW,GAAG,OAAO,KAAK,YAAY,CAAC;WAC9D,KAAK;EACZ,8BAA8B,UAAU;;;;;;;;;;;;;;EAcxC,eAAe,UAAU;EACzB,8BAA8B,WAAW;;;;EAIzC,8BAA8B,OAAO;;;;;;;;;EASrC,8BAA8B,WAAW,GAAG,OAAO,OAAO,WAAW,CAAC;WAC/D,OAAO;EACd,8BAA8B,OAAO;;;;;;;;;;EAUrC,8BAA8B,WAAW,GAAG,OAAO,OAAO,UAAU,CAAC;WAC9D,OAAO;EACd,8BAA8B,iBAAiB;;;;;;EAM/C,8BAA8B,UAAU;;;;;;;;;;;EAWxC,8BAA8B,WAAW,GAAG,OAAO,UAAU,UAAU,CAAC;WACjE,UAAU;EACjB,8BAA8B,gBAAgB;;;;;;;;;;;;;;;EAe9C,8BAA8B,WAC5B,GAAG,OAAO,gBAAgB,YAC3B,CAAC;WACK,gBAAgB;EACvB,eAAe,iBAAiB;;;;;;;;;;;;;EAajC,CAAC,IAAI,sBAAsB;;AAG9B,SAAgB,mBAAmB,QAA4B,OAAe;AAC5E,QAAO,SACH,GAAG,WAAW,OAAO,CAAC,GAAG,WAAW,MAAM,KAC1C,WAAW,MAAM;;AAGvB,SAAS,WAAW,YAAoB;AACtC,QAAO,IAAI,WAAW,WAAW,MAAK,OAAK,CAAC;;AAG9C,SAAS,sBAAsB,WAAmB;AAChD,QAAO,UACJ,MAAM,KAAK,CACX,KAAK,MAAM,UACV,UAAU,IAAI,KAAK,SAAS,GAAG,KAAK,QAAQ,SAAS,GAAG,CAAC,SAAS,CACnE,CACA,KAAK,KAAK"}
@@ -0,0 +1,22 @@
1
+ //#region src/schema-contract.d.ts
2
+ interface DrizzlePostgresWorkflowStoreTables {
3
+ schemaMigrations: string;
4
+ runs: string;
5
+ runStates: string;
6
+ eventLocks: string;
7
+ events: string;
8
+ timers: string;
9
+ signalDeliveries: string;
10
+ schedules: string;
11
+ scheduleBuckets: string;
12
+ }
13
+ interface DrizzlePostgresWorkflowStoreSchemaOptions {
14
+ schema?: string;
15
+ tables?: Partial<DrizzlePostgresWorkflowStoreTables>;
16
+ }
17
+ declare const defaultDrizzlePostgresWorkflowStoreTables: DrizzlePostgresWorkflowStoreTables;
18
+ declare function resolveDrizzlePostgresWorkflowStoreTables(tables?: Partial<DrizzlePostgresWorkflowStoreTables>): DrizzlePostgresWorkflowStoreTables;
19
+ declare function getDrizzlePostgresWorkflowStoreSchemaStatements(options?: DrizzlePostgresWorkflowStoreSchemaOptions): Array<string>;
20
+ //#endregion
21
+ export { DrizzlePostgresWorkflowStoreSchemaOptions, DrizzlePostgresWorkflowStoreTables, defaultDrizzlePostgresWorkflowStoreTables, getDrizzlePostgresWorkflowStoreSchemaStatements, resolveDrizzlePostgresWorkflowStoreTables };
22
+ //# sourceMappingURL=schema-contract.d.cts.map
@@ -0,0 +1,22 @@
1
+ //#region src/schema-contract.d.ts
2
+ interface DrizzlePostgresWorkflowStoreTables {
3
+ schemaMigrations: string;
4
+ runs: string;
5
+ runStates: string;
6
+ eventLocks: string;
7
+ events: string;
8
+ timers: string;
9
+ signalDeliveries: string;
10
+ schedules: string;
11
+ scheduleBuckets: string;
12
+ }
13
+ interface DrizzlePostgresWorkflowStoreSchemaOptions {
14
+ schema?: string;
15
+ tables?: Partial<DrizzlePostgresWorkflowStoreTables>;
16
+ }
17
+ declare const defaultDrizzlePostgresWorkflowStoreTables: DrizzlePostgresWorkflowStoreTables;
18
+ declare function resolveDrizzlePostgresWorkflowStoreTables(tables?: Partial<DrizzlePostgresWorkflowStoreTables>): DrizzlePostgresWorkflowStoreTables;
19
+ declare function getDrizzlePostgresWorkflowStoreSchemaStatements(options?: DrizzlePostgresWorkflowStoreSchemaOptions): Array<string>;
20
+ //#endregion
21
+ export { DrizzlePostgresWorkflowStoreSchemaOptions, DrizzlePostgresWorkflowStoreTables, defaultDrizzlePostgresWorkflowStoreTables, getDrizzlePostgresWorkflowStoreSchemaStatements, resolveDrizzlePostgresWorkflowStoreTables };
22
+ //# sourceMappingURL=schema-contract.d.ts.map