Skip to content

Commit c8fe144

Browse files
Edwin Chanclaude
authored andcommitted
docs: update SETUP.md for db push flow + new asset table
- Replace `prisma migrate deploy` with the `prisma db push` flow this repo actually uses (no migrations directory exists) - Add a "Deploying this pull" callout for ProblemSetAsset: run db push then prisma generate then pm2 reload, with a verification psql - Note the pm2-stale-client failure mode (today's API 500 was caused by reloading code without regenerating the Prisma client) and put the fix in §10 troubleshooting Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 17d7a10 commit c8fe144

1 file changed

Lines changed: 39 additions & 16 deletions

File tree

SETUP.md

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ Generate the secret if you don't have one:
5252
openssl rand -base64 32
5353
```
5454

55-
## 3. Install + migrate + build
55+
## 3. Install + schema + build
5656

5757
```bash
5858
npm ci
59-
npx prisma migrate deploy # applies committed migrations
6059
npx prisma generate
60+
npx prisma db push # creates / updates the schema
6161
npm run build
6262
```
6363

64-
If the database is fresh and there are no migration files yet, use `npx prisma db push` once to create the schema, then commit a baseline migration on your dev box later.
64+
This repo uses `prisma db push` (not `prisma migrate`). See §7 for why
65+
and how to handle subsequent schema changes.
6566

6667
## 4. Start with PM2
6768

@@ -154,34 +155,56 @@ sudo certbot --nginx -d your.domain.example
154155
cd ~/dbsmo
155156
git pull origin main
156157
npm ci
157-
npx prisma migrate deploy # only does work if there are new migrations
158+
npx prisma generate # regen client when schema.prisma changes
159+
npx prisma db push # apply schema (this repo uses db push, not migrate)
158160
npm run build
159161
pm2 reload dbsmo # zero-downtime reload
160162
pm2 logs dbsmo --lines 30
161163
```
162164

163165
If you only changed CSS or a static asset, `pm2 restart dbsmo` is fine.
164166

165-
## 7. Database migrations after schema changes
167+
> **Important:** `prisma generate` must run before `pm2 reload` whenever
168+
> `schema.prisma` changes. The pm2 process loads `@prisma/client` once at
169+
> startup; if you skip generate, the client won't know about new models
170+
> and any API touching them will return 500.
166171
167-
After pulling code that includes `prisma/schema.prisma` changes:
172+
### Deploying this pull (image-asset support)
173+
174+
This commit adds the `ProblemSetAsset` table and a few related fields.
175+
Run the standard redeploy block above — `prisma db push` will create the
176+
new table and indexes, `prisma generate` rebuilds the client, and the
177+
pm2 reload picks up the new code. Verify with:
168178

169179
```bash
170-
npx prisma migrate deploy
180+
psql -U dbsmo -h localhost dbsmo -c '\d "ProblemSetAsset"'
171181
```
172182

173-
If there's no migration file (this repo has been using `db push`-style flow during dev), generate one on your dev box first:
183+
You should see columns `id, problemSetId, key, fileId, createdAt`.
174184

175-
```bash
176-
# on dev
177-
npx prisma migrate dev --name <describe-change>
178-
git add prisma/migrations && git commit -m "db: <describe-change>"
179-
git push
185+
## 7. Database schema changes
186+
187+
This repo uses `prisma db push` (not `prisma migrate`), so any
188+
`schema.prisma` change applies the same way every time:
180189

181-
# on VPS
182-
git pull && npx prisma migrate deploy && pm2 reload dbsmo
190+
```bash
191+
git pull
192+
npx prisma generate # regen the client
193+
npx prisma db push # apply schema to the live DB
194+
pm2 reload dbsmo
183195
```
184196

197+
`db push` is idempotent — running it when nothing changed is a no-op.
198+
It does **not** drop columns unless you explicitly accept the prompt,
199+
so it's safe for additive changes (new tables, new optional columns,
200+
new indexes). Back up first (`pg_dump`, see §8) if a change is
201+
destructive or you're not sure.
202+
203+
If you ever need to switch this repo to migration files, run
204+
`prisma migrate dev --name baseline` on dev *once* to capture the
205+
current state, commit `prisma/migrations/`, and from then on use
206+
`prisma migrate deploy` on the VPS.
207+
185208
## 8. Backups
186209

187210
```bash
@@ -208,4 +231,4 @@ Cron it:
208231
- **Build OOM on VPS** — small VPS? `NODE_OPTIONS="--max-old-space-size=2048" npm run build`.
209232
- **Prisma can't connect** — verify `DATABASE_URL`, run `psql "$DATABASE_URL" -c '\dt'` to confirm credentials.
210233
- **Google sign-in loops**`NEXTAUTH_URL` must be your public HTTPS URL exactly, and the OAuth redirect URI in Google Cloud must include `https://your.domain.example/api/auth/callback/google`.
211-
- **Schema out of sync**`npx prisma migrate status` to see what's pending.
234+
- **Schema out of sync**re-run `npx prisma db push` then `pm2 reload dbsmo`. If `pm2 logs --err` shows "Unknown field" or "Unknown model", the running pm2 process is loading a stale `@prisma/client`. Run `npx prisma generate` then `pm2 reload dbsmo`.

0 commit comments

Comments
 (0)