Database
I’ll first inspect the @database package files (config, CLI, schema, env) to understand how it’s meant to be used, then I’ll write a concise markdown doc you can drop into your repo.
[5 tools called]
@database/prisma – Usage Guide
This document explains how to use the @database/prisma package for database management and app configuration in this boilerplate.
Installation & Setup
Go to the packages/database directory:
- Install dependencies (root of repo):
npm install- Environment variables:
Copy the example env file and set your database URL:
cd packages/database
cp .env.example .envThen edit .env:
DIRECT_URL="postgresql://USER:PASSWORD@HOST:5432/postgres"DIRECT_URL must point to your Postgres (Supabase) instance.
Prisma Configuration
- Config file:
prisma.config.ts
Key parts:
export default defineConfig({
schema: "prisma/schema.prisma",
datasource: {
url: env("DIRECT_URL"),
},
migrations: {
path: "prisma/migrations",
seed: "tsx src/seed.ts",
},
});- Prisma uses
DIRECT_URLfor all DB operations. - Migrations live under
prisma/migrations. src/seed.tsis the default seeding script.src/cli.tsis the interactive config CLI.
NPM Scripts (from package.json)
Run these from packages/database:
- Apply production migrations:
npm run db:migrate:deploy- Development migrations (interactive):
npm run db:migrate:dev- Push schema without migrations (dev only):
npm run db:push- Seed database:
npm run db:seed- Open Prisma Studio:
npm run studio- Generate Prisma client:
npm run generate- Run interactive config CLI:
npm run cliSeeding App Configs (src/seed.ts)
src/seed.ts:
- Connects to Postgres via
@prisma/adapter-pgusingDIRECT_URL. - Clears existing
appConfigentries with:
await prisma.appConfig.deleteMany({});- Inserts a predefined set of configs (Apple, Google, Twitter, RevenueCat, OneSignal, PostHog, Sentry, API base URL,
app.version,app.campaign) usingConfigTypeenums.
Usage:
cd packages/database
npm run db:seedThis will wipe and recreate all
appConfigrows. Comment outdeleteManyif you need to preserve existing data.
Interactive App Config CLI (src/cli.ts)
The CLI provides a TUI to manage appConfig records.
Prerequisites
.envwith a validDIRECT_URL- Generated Prisma client at
prisma/generated/client(runnpm run generateif missing)
Start the CLI
cd packages/database
npm run cliFeatures
-
Insert new config
- Prompts:
key(string, required)value(string, required)type(one of:STRING,NUMBER,BOOLEAN,JSON,URL,EMAIL,DATE)description(optional)
- Validates:
NUMBER→ numericBOOLEAN→true/false/1/0/yes/noJSON→ valid JSONURL→ valid URLEMAIL→ valid email formatDATE→ parsable date string
- Confirms before insert and writes to
appConfig.
- Prompts:
-
View all configs
- Lists all configs in a table:
KEY,TYPE, truncatedVALUE, truncatedDESCRIPTION
- Optionally allows selecting a key to view full details (including formatted JSON values and timestamps).
- Lists all configs in a table:
-
Exit
- Cleanly terminates the process.
Typical Workflow
-
Initial setup for a new environment:
- Configure
.envwithDIRECT_URL. - Run
npm run db:migrate:deploy(ordb:migrate:devin development). - Run
npm run db:seedto populate baseappConfigentries.
- Configure
-
Managing runtime configs later:
- Run
npm run cli. - Use “Insert new config” to add new keys.
- Use “View all configs” to inspect existing values.
- Run
When to Touch @database/prisma
-
Modify
prisma/schema.prismawhen:- Adding/removing tables or fields.
- Changing the shape of
appConfigor other models.
-
Run migrations / generate client after schema changes:
npm run db:migrate:dev(dev) ordb:migrate:deploy(prod).npm run generateto update the typed client.
-
Use
seed.tsandcli.tsto keep application configuration centralized and consistent across environments.