@@ -43,8 +43,12 @@ import { createDrizzlePostgresWorkflowStore } from '@tanstack/workflow-store-dri
4343
4444const db = drizzle (new Pool ({ connectionString: process .env .DATABASE_URL }))
4545const store = createDrizzlePostgresWorkflowStore ({ db })
46+ ```
4647
47- await store .ensureSchema ()
48+ Apply the package-owned migration during setup/deploy:
49+
50+ ``` bash
51+ psql " $DATABASE_URL " -f node_modules/@tanstack/workflow-store-drizzle-postgres/migrations/0000_workflow_store.sql
4852```
4953
5054Use it in the runtime:
@@ -76,6 +80,74 @@ Options:
7680| ` schema ` | Optional Postgres schema name. |
7781| ` tables ` | Optional table name overrides. |
7882
83+ ## Package-owned migrations
84+
85+ The Drizzle/Postgres package owns the durable Workflow schema. Apps should apply
86+ the SQL artifact from the installed package instead of mirroring ` workflow_* `
87+ tables in application Drizzle schema files.
88+
89+ ``` bash
90+ psql " $DATABASE_URL " -f node_modules/@tanstack/workflow-store-drizzle-postgres/migrations/0000_workflow_store.sql
91+ ```
92+
93+ Programmatic setup can use the exported migration helpers:
94+
95+ ``` ts
96+ import {
97+ getDrizzlePostgresWorkflowStoreMigrationSql ,
98+ getDrizzlePostgresWorkflowStoreMigrations ,
99+ } from ' @tanstack/workflow-store-drizzle-postgres'
100+ ```
101+
102+ Schema changes are versioned with ` @tanstack/workflow-store-drizzle-postgres ` .
103+ Apply new package migrations when upgrading the adapter. Runtime code assumes the
104+ database schema is compatible with the installed store adapter version.
105+
106+ The initial migration creates ` workflow_schema_migrations ` and records applied
107+ Workflow store migrations. Future migrations will be appended as new numbered SQL
108+ files in the package. Apply them in order during deploy/setup before running the
109+ new adapter version.
110+
111+ Maintainers changing the Drizzle/Postgres store schema should follow the
112+ package-local ` SCHEMA_MIGRATIONS.md ` checklist.
113+
114+ ## Cloudflare D1
115+
116+ Install:
117+
118+ ``` bash
119+ pnpm add @tanstack/workflow-store-cloudflare-d1
120+ ```
121+
122+ Create the store from a D1 binding:
123+
124+ ``` ts
125+ import { createCloudflareD1WorkflowStore } from ' @tanstack/workflow-store-cloudflare-d1'
126+
127+ const store = createCloudflareD1WorkflowStore ({
128+ db: env .WORKFLOW_DB ,
129+ })
130+ ```
131+
132+ Apply the package-owned D1 migration during setup/deploy:
133+
134+ ``` txt
135+ node_modules/@tanstack/workflow-store-cloudflare-d1/migrations/0000_workflow_store.sql
136+ ```
137+
138+ Programmatic setup can use the exported migration helpers:
139+
140+ ``` ts
141+ import {
142+ getCloudflareD1WorkflowStoreMigrationSql ,
143+ getCloudflareD1WorkflowStoreMigrations ,
144+ } from ' @tanstack/workflow-store-cloudflare-d1'
145+ ```
146+
147+ D1 stores JSON payloads as text and uses SQLite integer timestamps. Its claim
148+ operations use atomic conditional updates and leases rather than Postgres
149+ ` FOR UPDATE SKIP LOCKED ` .
150+
79151## ` store.ensureSchema `
80152
81153Creates the required tables and indexes if they do not exist.
@@ -84,17 +156,17 @@ Creates the required tables and indexes if they do not exist.
84156await store .ensureSchema ()
85157```
86158
87- Use this from an explicit app-owned bootstrap/admin script, not from every
88- request or sweep. Runtime and host adapters assume the schema exists. In
89- production, you may want to run equivalent SQL through your migration system
90- instead of calling this at application startup.
159+ Use this from tests, local demos, or an explicit admin bootstrap script, not
160+ from every request or sweep. Runtime and host adapters assume the schema exists.
161+ Production deploys should prefer the package-owned SQL migration artifact.
91162
92163## Default tables
93164
94165` defaultDrizzlePostgresWorkflowStoreTables ` contains:
95166
96167| Table key | Default table |
97168| --- | --- |
169+ | ` schemaMigrations ` | ` workflow_schema_migrations ` |
98170| ` runs ` | ` workflow_runs ` |
99171| ` runStates ` | ` workflow_run_states ` |
100172| ` eventLocks ` | ` workflow_event_locks ` |
@@ -104,6 +176,23 @@ instead of calling this at application startup.
104176| ` schedules ` | ` workflow_schedules ` |
105177| ` scheduleBuckets ` | ` workflow_schedule_buckets ` |
106178
179+ ## Optional Drizzle table definitions
180+
181+ The package exports Drizzle table definitions for apps that explicitly want
182+ typed read access for dashboards, diagnostics, or admin tooling:
183+
184+ ``` ts
185+ import {
186+ workflowEvents ,
187+ workflowRuns ,
188+ workflowSchedules ,
189+ workflowSchemaMigrations ,
190+ } from ' @tanstack/workflow-store-drizzle-postgres'
191+ ```
192+
193+ These exports are optional. Normal runtime use does not require adding Workflow
194+ tables to your app schema.
195+
107196## In-memory store
108197
109198For tests and demos:
0 commit comments