Skip to content

Commit 76f5ff1

Browse files
committed
feat: initialize Prisma in packages/database with Docker Postgres
- add docker-compose.yml for Postgres 18 (alpine) - initialize Prisma ORM in packages/database with pg adapter - add User placeholder model + first migration - document module resolution and generator gotchas in SETUP.md
1 parent d05a379 commit 76f5ff1

103 files changed

Lines changed: 13254 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.env.example‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
POSTGRES_USER=kaeru
2+
POSTGRES_PASSWORD=kaeru_dev_password
3+
POSTGRES_DB=kaeru
4+
POSTGRES_PORT=5432

‎Makefile‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.PHONY: db-up db-down db-logs
2+
3+
db-up:
4+
docker compose up -d postgres
5+
6+
db-down:
7+
docker compose down
8+
9+
db-logs:
10+
docker compose logs -f postgres

‎docker-compose.yml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
postgres:
3+
image: postgres:18-alpine
4+
container_name: kaeru-postgres
5+
restart: unless-stopped
6+
environment:
7+
POSTGRES_USER: ${POSTGRES_USER:-kaeru}
8+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-kaeru_dev_password}
9+
POSTGRES_DB: ${POSTGRES_DB:-kaeru}
10+
ports:
11+
- "${POSTGRES_PORT:-5432}:5432"
12+
volumes:
13+
- postgres_data:/var/lib/postgresql
14+
healthcheck:
15+
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-kaeru}"]
16+
interval: 5s
17+
timeout: 5s
18+
retries: 5
19+
20+
volumes:
21+
postgres_data:

‎docs/SETUP.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## packages/database - gotchas
2+
3+
- **moduleResolution**: set to `"bundler"` in tsconfig.json, not the
4+
`tsc --init` default. This package is only ever consumed through
5+
Next.js/Turbopack, never run directly with plain `node`, so bundler
6+
resolution is correct - it understands package.json `exports` maps
7+
(needed for `dotenv/config`, `prisma/config`) without requiring
8+
explicit file extensions on every relative import.
9+
10+
- **Prisma client import path**: schema.prisma uses the `prisma-client`
11+
generator, which outputs a flat structure - `generated/client/client.ts`
12+
is the documented main entry point, there is no `index.ts` barrel.
13+
Always import from `./generated/client/client`, not `./generated/client`.
14+
This will look wrong at a glance; it isn't.
15+
16+
- **Postgres 18 volume mount**: docker-compose.yml mounts the volume at
17+
`/var/lib/postgresql` (not `/var/lib/postgresql/data`). Postgres 18+
18+
manages a version-specific subdirectory itself; mounting directly at
19+
the old `/data` path causes a crash-loop.
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
---
2+
name: prisma-cli
3+
description: Prisma ORM CLI commands reference covering init, generate, migrate, db, dev, studio, validate, format, debug, and mcp. Use for ORM/database CLI workflows, not Prisma Compute app deployment. For Prisma Compute, `@prisma/cli app deploy`, `compute:deploy`, `create-prisma --deploy`, apps, deployments, logs, or domains, use the `prisma-compute` skill instead. Triggers on "prisma init", "prisma generate", "prisma migrate", "prisma db", "prisma studio", "prisma mcp".
4+
license: MIT
5+
metadata:
6+
author: prisma
7+
version: "7.6.0"
8+
---
9+
10+
# Prisma CLI Reference
11+
12+
Reference for Prisma ORM CLI commands. This skill provides guidance on command usage, options, and best practices for current Prisma ORM releases.
13+
14+
## Boundary: Compute
15+
16+
Do not use this skill for Prisma Compute app deployment. Use `prisma-compute` for `@prisma/cli app deploy`, `compute:deploy`, `create-prisma --deploy`, Compute apps, deployments, logs, domains, and framework deploy readiness.
17+
18+
## When to Apply
19+
20+
Reference this skill when:
21+
- Setting up a new Prisma project (`prisma init`)
22+
- Generating Prisma Client (`prisma generate`)
23+
- Running database migrations (`prisma migrate`)
24+
- Managing database state (`prisma db push/pull`)
25+
- Using local development database (`prisma dev`)
26+
- Debugging Prisma issues (`prisma debug`)
27+
28+
## Rule Categories by Priority
29+
30+
| Priority | Category | Impact | Prefix |
31+
|----------|----------|--------|--------|
32+
| 1 | Setup | HIGH | `init` |
33+
| 2 | Generation | HIGH | `generate` |
34+
| 3 | Development | HIGH | `dev` |
35+
| 4 | Database | HIGH | `db-` |
36+
| 5 | Migrations | CRITICAL | `migrate-` |
37+
| 6 | Utility | MEDIUM | `studio`, `validate`, `format`, `debug`, `mcp` |
38+
39+
## Command Categories
40+
41+
| Category | Commands | Purpose |
42+
|----------|----------|---------|
43+
| Setup | `init` | Bootstrap new Prisma project |
44+
| Generation | `generate` | Generate Prisma Client |
45+
| Validation | `validate`, `format` | Schema validation and formatting |
46+
| Development | `dev` | Local Prisma Postgres for development |
47+
| Database | `db pull`, `db push`, `db seed`, `db execute` | Direct database operations |
48+
| Migrations | `migrate dev`, `migrate deploy`, `migrate reset`, `migrate status`, `migrate diff`, `migrate resolve` | Schema migrations |
49+
| Utility | `studio`, `mcp`, `version`, `debug` | Development and AI tooling |
50+
51+
## Quick Reference
52+
53+
### Project Setup
54+
55+
```bash
56+
# Initialize new project (creates prisma/ folder and prisma.config.ts)
57+
prisma init
58+
59+
# Initialize with specific database
60+
prisma init --datasource-provider postgresql
61+
prisma init --datasource-provider mysql
62+
prisma init --datasource-provider sqlite
63+
64+
# Initialize with Prisma Postgres (cloud)
65+
prisma init --db
66+
67+
# Initialize with an example model
68+
prisma init --with-model
69+
```
70+
71+
### Client Generation
72+
73+
```bash
74+
# Generate Prisma Client
75+
prisma generate
76+
77+
# Watch mode for development
78+
prisma generate --watch
79+
80+
# Generate specific generator only
81+
prisma generate --generator client
82+
```
83+
84+
### Bun Runtime
85+
86+
When using Bun, always add the `--bun` flag so Prisma runs with the Bun runtime (otherwise it falls back to Node.js because of the CLI shebang):
87+
88+
```bash
89+
bunx --bun prisma init
90+
bunx --bun prisma generate
91+
```
92+
93+
### Local Development Database
94+
95+
```bash
96+
# Start local Prisma Postgres
97+
prisma dev
98+
99+
# Start with specific name
100+
prisma dev --name myproject
101+
102+
# Start in background (detached)
103+
prisma dev --detach
104+
105+
# List all local instances
106+
prisma dev ls
107+
108+
# Stop instance
109+
prisma dev stop myproject
110+
111+
# Remove instance data
112+
prisma dev rm myproject
113+
```
114+
115+
### Database Operations
116+
117+
```bash
118+
# Pull schema from existing database
119+
prisma db pull
120+
121+
# Push schema to database (no migrations)
122+
prisma db push
123+
124+
# Seed database
125+
prisma db seed
126+
127+
# Execute raw SQL
128+
prisma db execute --file ./script.sql
129+
```
130+
131+
### Migrations (Development)
132+
133+
```bash
134+
# Create and apply migration
135+
prisma migrate dev
136+
137+
# Create migration with name
138+
prisma migrate dev --name add_users_table
139+
140+
# Create migration without applying
141+
prisma migrate dev --create-only
142+
143+
# Reset database and apply all migrations
144+
prisma migrate reset
145+
```
146+
147+
### Migrations (Production)
148+
149+
```bash
150+
# Apply pending migrations (CI/CD)
151+
prisma migrate deploy
152+
153+
# Check migration status
154+
prisma migrate status
155+
156+
# Compare schemas and generate diff
157+
prisma migrate diff --from-config-datasource --to-schema schema.prisma --script
158+
```
159+
160+
### Utility Commands
161+
162+
```bash
163+
# Open Prisma Studio (database GUI)
164+
prisma studio
165+
166+
# Start Prisma's MCP server for AI tools
167+
prisma mcp
168+
169+
# Show version info
170+
prisma version
171+
prisma -v
172+
173+
# Debug information
174+
prisma debug
175+
176+
# Validate schema
177+
prisma validate
178+
179+
# Format schema
180+
prisma format
181+
```
182+
183+
## Current Prisma CLI Setup
184+
185+
### New Configuration File
186+
187+
Use `prisma.config.ts` for CLI configuration:
188+
189+
```typescript
190+
import 'dotenv/config'
191+
import { defineConfig, env } from 'prisma/config'
192+
193+
export default defineConfig({
194+
schema: 'prisma/schema.prisma',
195+
migrations: {
196+
path: 'prisma/migrations',
197+
seed: 'tsx prisma/seed.ts',
198+
},
199+
datasource: {
200+
url: env('DATABASE_URL'),
201+
},
202+
})
203+
```
204+
205+
### Current Command Behavior
206+
207+
- Run `prisma generate` explicitly after `migrate dev`, `db push`, or other schema syncs when you need fresh client output
208+
- Run `prisma db seed` explicitly after `migrate dev` or `migrate reset` when you need seed data
209+
- Use `prisma db execute --file ...` for raw SQL scripts
210+
211+
### Environment Variables
212+
213+
Load environment variables explicitly in `prisma.config.ts`, commonly with `dotenv`:
214+
215+
```typescript
216+
// prisma.config.ts
217+
import 'dotenv/config'
218+
```
219+
220+
## Rule Files
221+
222+
See individual rule files for detailed command documentation:
223+
224+
```
225+
references/init.md - Project initialization
226+
references/generate.md - Client generation
227+
references/dev.md - Local development database
228+
references/db-pull.md - Database introspection
229+
references/db-push.md - Schema push
230+
references/db-seed.md - Database seeding
231+
references/db-execute.md - Raw SQL execution
232+
references/migrate-dev.md - Development migrations
233+
references/migrate-deploy.md - Production migrations
234+
references/migrate-reset.md - Database reset
235+
references/migrate-status.md - Migration status
236+
references/migrate-resolve.md - Migration resolution
237+
references/migrate-diff.md - Schema diffing
238+
references/studio.md - Database GUI
239+
references/mcp.md - Prisma MCP server
240+
references/validate.md - Schema validation
241+
references/format.md - Schema formatting
242+
references/debug.md - Debug info
243+
```
244+
245+
## How to Use
246+
247+
Use the command categories above for navigation, then open the specific command reference file you need.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# prisma db execute
2+
3+
Execute native commands (SQL) to your database.
4+
5+
## Command
6+
7+
```bash
8+
prisma db execute [options]
9+
```
10+
11+
## What It Does
12+
13+
- Connects to your database using the configured datasource
14+
- Executes a script provided via file (`--file`) or stdin (`--stdin`)
15+
- Useful for running raw SQL, maintenance tasks, or applying diffs from `migrate diff`
16+
- Not supported on MongoDB
17+
18+
## Options
19+
20+
| Option | Description |
21+
|--------|-------------|
22+
| `--file` | Path to a file containing the script to execute |
23+
| `--stdin` | Use terminal standard input as the script |
24+
| `--config` | Custom path to your Prisma config file |
25+
26+
## Current Option Surface
27+
28+
`prisma db execute` uses the datasource configured in `prisma.config.ts`. Use `--config` if you need a separate config file for another environment.
29+
30+
## Examples
31+
32+
### Execute from file
33+
34+
```bash
35+
prisma db execute --file ./script.sql
36+
```
37+
38+
### Execute from stdin
39+
40+
```bash
41+
echo "TRUNCATE TABLE User;" | prisma db execute --stdin
42+
```
43+
44+
### Execute `migrate diff` output
45+
46+
Pipe the output of `migrate diff` directly to the database:
47+
48+
```bash
49+
prisma migrate diff \
50+
--from-empty \
51+
--to-schema prisma/schema.prisma \
52+
--script \
53+
| prisma db execute --stdin
54+
```
55+
56+
## Configuration
57+
58+
Uses `datasource` from `prisma.config.ts`:
59+
60+
```typescript
61+
export default defineConfig({
62+
datasource: {
63+
url: env('DATABASE_URL'),
64+
},
65+
})
66+
```
67+
68+
## Use Cases
69+
70+
- **Manual Migrations**: Applying raw SQL changes
71+
- **Data Maintenance**: Truncating tables, cleaning up data
72+
- **Schema Synchronization**: Applying `migrate diff` scripts
73+
- **Debugging**: Running test queries (though typically not for fetching data)
74+
75+
## Limitations
76+
77+
- **No Data Return**: The command reports success/failure, not query results (rows). Use Prisma Client or `prisma studio` to view data.
78+
- **SQL Only**: Primarily for SQL databases.

0 commit comments

Comments
 (0)