Skip to content

Custom tables

Use custom tables for records your organisation maintains, such as orders or inventory. Processes can write to these tables, and Lists can present the records in the Dashboard. Custom tables live in the same database as Process Focus system tables.

In a project created with pfcli init, Drizzle Kit reads the exported table definitions in src/schema/schema.ts. Add Drizzle ORM as a project dependency if it isn’t already installed:

Terminal window
bun add drizzle-orm@1.0.0-rc.6

Add this table to src/schema/schema.ts:

import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"
export const webOrders = sqliteTable("web_orders", {
id: text().primaryKey(),
sku: text().notNull(),
quantity: integer().notNull(),
})

Use sqliteTable for the default local and cloud setup. If you’re defining the table for PostgreSQL, use pgTable instead:

import { integer, pgTable, text } from "drizzle-orm/pg-core"
export const webOrders = pgTable("web_orders", {
id: text().primaryKey(),
sku: text().notNull(),
quantity: integer().notNull(),
})

After adding or changing a table, generate a migration from the organisation directory. For the default SQLite configuration, run:

Terminal window
SQLITE_DATABASE_PATH=./db/pf.db bunx drizzle-kit generate

Review the generated SQL and commit the files in drizzle/ with the schema change. In the default SQLite setup, local pfcli import and Process Focus cloud deployments apply pending migrations automatically.

For the pgTable example, generate PostgreSQL migrations in a separate directory so Drizzle Kit does not reuse SQLite migration history:

Terminal window
bunx drizzle-kit generate --dialect=postgresql --schema=./src/schema/schema.ts --out=./drizzle-postgres

Generation does not need a database connection. Review and commit the files in drizzle-postgres/ with the schema change, then apply them through your PostgreSQL migration workflow.