This starter is a template for a Next.js project that uses Workflow DevKit with the Postgres World. It follows the Workflow DevKit: Next.js Getting Started Guide to bootstrap a new project, with the few additions necessary to run it with the Postgres world.
-
Clone this example and install dependencies:
git clone https://github.com/vercel/workflow-examples cd workflow-examples/postgres bun install -
Spin up a PostgreSQL database locally or online and obtain the connection URL.
It should look something like
postgresql://<username>:<password>@<host>:<port>/<database>. -
Set the environment variables for the Postgres world:
export WORKFLOW_TARGET_WORLD="@workflow/world-postgres" export WORKFLOW_POSTGRES_URL="postgresql://<username>:<password>@<host>:<port>/<database>"
-
Run the database setup command to create or update the Workflow tables:
bun run migrate
Run this again after upgrading
@workflow/world-postgresso your database schema stays in sync. -
Start the development server:
bun dev
The example uses
instrumentation.tsto start the Postgres world worker when the Next.js server boots. -
Invoke the workflow by
curl:curl -X POST --json '{"email":"hello@example.com"}' http://localhost:3000/api/signup -
Inspect the stored runs if you want to confirm the workflow completed:
bunx workflow inspect runs --backend @workflow/world-postgres
The postgres world is incompatible with Vercel deployments (on Vercel, workflow deployments are automatically configured to use the Vercel World with zero configuration).
This example is also available as a Railway template that deploys:
- the
postgresdemo app - a PostgreSQL database for the Postgres World
- a separate observability deployment for inspecting runs
After deploying the template, trigger a workflow run against your app deployment:
curl -X POST \
-H 'content-type: application/json' \
--data '{"email":"your-test@example.com"}' \
https://YOUR-APP-URL/api/signupYou should get back:
{"message":"User signup workflow started"}Then open your observability deployment URL to watch the run progress and confirm that it completes successfully.