Skip to Content

next-workflow-builder

DevKit AI Builder Template DocumentationMarketplace
CTRL K
Demo
CTRL K
  • DevKit 
  • AI Builder Template 
    • Introduction
    • Getting Started
    • Configuration
    • Plugins
      • Overview
      • HTTP Request
      • Condition
      • Loop
      • Merge
      • Database Query
      • Run Workflow
      • Run Workflows in Sequence
      • Switch
    • Creating Plugins
    • API Reference
    • CLI Reference
    • Components
    • Database
    • Authentication
    • Deployment
    • Architecture
    • Contributing
    • MCP Server
  • Marketplace
  • Introduction
  • Getting Started
  • Configuration
  • Plugins
    • Overview
    • HTTP Request
    • Condition
    • Loop
    • Merge
    • Database Query
    • Run Workflow
    • Run Workflows in Sequence
    • Switch
  • Creating Plugins
  • API Reference
  • CLI Reference
  • Components
  • Database
  • Authentication
  • Deployment
  • Architecture
  • Contributing
  • MCP Server

On This Page

  • Connection
  • Drizzle configuration
  • Schema
  • Tables
  • users
  • sessions
  • workflows
  • integrations
  • workflowExecutions
  • workflowExecutionLogs
  • apiKeys
  • Migrations
  • Generating migrations
  • Applying migrations
  • Convenience scripts
  • Production
  • Using the database instance
  • Credential encryption
Question? Give us feedback Edit this page 
DocumentationDatabase

Database

next-workflow-builder uses PostgreSQL with Drizzle ORM for data storage.

Connection

Set the DATABASE_URL environment variable:

DATABASE_URL=postgres://user:password@localhost:5432/workflow

The package connects automatically using this URL. No manual database setup code is required.

Alternatively, you can pass the connection URL directly in your next.config.ts:

const withNextWorkflowBuilder = nextWorkflowBuilder({ databaseUrl: process.env.DATABASE_URL, });

When databaseUrl is provided, it takes priority over the DATABASE_URL environment variable.

Drizzle configuration

The package ships a ready-to-use drizzle.config.ts — no need to create your own. All Drizzle Kit commands can reference it directly:

pnpm drizzle-kit generate --config=node_modules/next-workflow-builder/drizzle.config.ts

If you prefer a local config (e.g. to customize the output directory), create a drizzle.config.ts at your project root:

// drizzle.config.ts import { config } from "dotenv"; import type { Config } from "drizzle-kit"; config(); export default { schema: "next-workflow-builder/server/db/schema", out: "./drizzle", dialect: "postgresql", dbCredentials: { url: process.env.DATABASE_URL || "postgres://localhost:5432/workflow", }, } satisfies Config;

Schema

Database tables are exported from next-workflow-builder/server:

import { users, sessions, accounts, verifications, workflows, integrations, workflowExecutions, workflowExecutionLogs, apiKeys, db, } from "next-workflow-builder/server";

Tables

users

Better Auth user accounts.

ColumnTypeDescription
idtextPrimary key
nametextDisplay name
emailtextUnique email address
emailVerifiedbooleanWhether email is verified
imagetextAvatar URL
isAnonymousbooleanWhether this is an anonymous user
createdAttimestampCreated timestamp
updatedAttimestampUpdated timestamp

sessions

Active user sessions.

ColumnTypeDescription
idtextPrimary key
tokentextUnique session token
userIdtextForeign key to users
expiresAttimestampSession expiry
ipAddresstextClient IP
userAgenttextClient user agent

workflows

User workflows with their canvas state.

ColumnTypeDescription
idtextPrimary key (auto-generated nanoid)
nametextWorkflow name
descriptiontextOptional description
userIdtextForeign key to users
nodesjsonbArray of React Flow nodes
edgesjsonbArray of React Flow edges
visibilitytext"private" or "public"
createdAttimestampCreated timestamp
updatedAttimestampUpdated timestamp

integrations

Stored integration credentials (encrypted).

ColumnTypeDescription
idtextPrimary key (auto-generated nanoid)
userIdtextForeign key to users
nametextConnection display name
typetextIntegration type slug (e.g. "slack", "github")
configjsonbEncrypted credential configuration
isManagedbooleanWhether this is a managed OAuth connection
createdAttimestampCreated timestamp
updatedAttimestampUpdated timestamp

workflowExecutions

Workflow execution history.

ColumnTypeDescription
idtextPrimary key
workflowIdtextForeign key to workflows
userIdtextForeign key to users
statustextExecution status
createdAttimestampCreated timestamp
updatedAttimestampUpdated timestamp

workflowExecutionLogs

Per-node execution logs within a workflow run.

ColumnTypeDescription
idtextPrimary key
executionIdtextForeign key to workflowExecutions
nodeIdtextNode that was executed
statustextNode execution status
outputjsonbNode output data
createdAttimestampCreated timestamp

apiKeys

Webhook API keys (stored as hashed values).

ColumnTypeDescription
idtextPrimary key
userIdtextForeign key to users
nametextKey display name
hashedKeytextHashed API key value
prefixtextKey prefix for display
createdAttimestampCreated timestamp

Additional tables for Better Auth (accounts, verifications) are also included.

Migrations

Generating migrations

After installing or upgrading next-workflow-builder, generate migration files to capture any schema changes:

pnpm drizzle-kit generate --config=node_modules/next-workflow-builder/drizzle.config.ts

If there are no schema changes, drizzle-kit will report “nothing to migrate” and no files are created.

Applying migrations

pnpm drizzle-kit migrate --config=node_modules/next-workflow-builder/drizzle.config.ts

Or push the schema directly without migration files (useful for rapid prototyping):

pnpm drizzle-kit push --config=node_modules/next-workflow-builder/drizzle.config.ts

Convenience scripts

Add shorthand scripts to your package.json to avoid repeating the config path:

{ "scripts": { "db:generate": "drizzle-kit generate --config=node_modules/next-workflow-builder/drizzle.config.ts", "db:migrate": "drizzle-kit migrate --config=node_modules/next-workflow-builder/drizzle.config.ts", "db:push": "drizzle-kit push --config=node_modules/next-workflow-builder/drizzle.config.ts", "db:studio": "drizzle-kit studio --config=node_modules/next-workflow-builder/drizzle.config.ts" } }

Then run:

pnpm db:generate # Generate migration files pnpm db:migrate # Apply migrations pnpm db:push # Push schema directly (skip migration files) pnpm db:studio # Open Drizzle Studio

Production

Run migrations with the CLI:

npx nwb migrate-prod

This reads DATABASE_URL and applies pending schema migrations.

Using the database instance

The db export provides a Drizzle ORM query builder with the full schema:

import { db, workflows } from "next-workflow-builder/server"; import { eq, desc } from "drizzle-orm"; const userWorkflows = await db.query.workflows.findMany({ where: eq(workflows.userId, userId), orderBy: desc(workflows.updatedAt), });

Credential encryption

Integration credentials stored in the integrations table are encrypted at rest using the INTEGRATION_ENCRYPTION_KEY environment variable:

import { encrypt, decrypt } from "next-workflow-builder/server"; const encrypted = encrypt(JSON.stringify(credentials)); const decrypted = JSON.parse(decrypt(encrypted));
Last updated on March 12, 2026
ComponentsAuthentication

© 2026 All rights reserved.

Product by David Sanchez