db-migrate
/db-migrate
Drizzle schema change workflow for SpawnForge Neon DB. Use when modifying schema.ts, generating migrations, applying migrations to production, or debugging FK/cascade issues.
- Author
- Tristan578 ↗
- Repository
- project-forge ↗
- Licence
- Apache-2.0
- Last repository change
- 17.10.2026
Assessment and security
- Files in this package
- 6
- Scripts
- 2
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 17.10.2026, without references to retired models or APIs.
Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.
- 2 scripts in this package. Review them before installing, as Claude may execute them.
Scripts: scripts/migration-validate.sh, scripts/schema-diff.sh
What it does and when to use it
Drizzle schema change workflow for SpawnForge Neon DB. Use when modifying schema.ts, generating migrations, applying migrations to production, or debugging FK/cascade issues.
Arguments
/db-migrate [action: generate|push|migrate|validate|status]
Original author description
Drizzle schema change workflow for SpawnForge Neon DB. Use when modifying schema.ts, generating migrations, applying migrations to production, or debugging FK/cascade issues.
How it works
- Before ANY Schema Change
- Actions
- FK Cascade Checklist
- Common Pitfalls
- Neon-Specific
SKILL.md preview
---
name: db-migrate
description: Drizzle schema change workflow for SpawnForge Neon DB. Use when modifying schema.ts, generating migrations, applying migrations to production, or debugging FK/cascade issues.
user-invocable: true
allowed-tools: Bash, Read, Glob, Grep, Edit
argument-hint: "[action: generate|push|migrate|validate|status]"
paths: "web/src/lib/db/**"
---
# Database Migration Workflow
Safe database schema changes for SpawnForge (Drizzle ORM + Neon Postgres).
## Before ANY Schema Change
1. Read the current schema: `web/src/lib/db/schema.ts`
2. FK cascade gaps have caused real incidents (PF-976, PF-974) — work through the FK Cascade Checklist below
3. Identify ALL tables that reference the table being modified
## Actions
### `validate` (default when no args)
Check schema for common issues:
```bash
cd web
# 1. Check for FK references without onDelete cascade
grep -n "references.*=>" src/lib/db/schema.ts | grep -v "onDelete"
# 2. Check deleteUserAccount cascade covers all tables with user_id FK
grep -n "user_id\|userId" src/lib/db/schema.ts | grep "references"
# Compare with:
grep -n "DELETE FROM\|delete(" src/lib/auth/user-service.ts
# 3. Check for tables with FKs not in the delete cascade
echo "--- Tables with user_id FK ---"
grep -B5 "userId.*references.*users" src/lib/db/schema.ts | grep "pgTable"
echo "--- Tables deleted in deleteUserAccount ---"
grep "DELETE FROM\|\.delete(" src/lib/auth/user-service.ts | grep -oE "'[a-z_]+'" | sort -u
# 4. Validate schema compiles
npx tsc --noEmit src/lib/db/schema.ts 2>&1 | head -20
```
### `generate`
Generate a migration from schema changes:
```bash
cd web
# 1. Validate schema first
npx tsc --noEmit
# 2. Generate migration SQL
npx drizzle-kit generate
# 3. Review the generated SQL
ls -t drizzle/*.sql | head -1 | xargs cat
# 4. CHECK: Does the migration add a new table with a user_id FK?
# If yes, it MUST be added to deleteUserAccount cascade in user-service.ts
```
### `push` (dev only — direct schema push, no migration file)
```bash
cd web && npx drizzle-kit push
```
Use only for local development. Never in production.
### `migrate` (production — applies migration files)
```bash
cd web && npm run db:migrate # runs the baseline-journal --guard-migrate check, then scripts/apply-migrations.ts
```
### `status`
```bash
cd web && npx drizzle-kit status
```
## FK Cascade Checklist
When adding a new table with `user_id` or any FK to `users.id`:
1. Add `DELETE FROM <table> WHERE user_id = ${userId}` to `deleteUserAccount()` in `web/src/lib/auth/user-service.ts`
2. Place the DELETE statement BEFORE the parent table's DELETE (dependency order)
3. If the new table has its own FK children, delete those first
4. Add the table to the schema test in `web/src/lib/db/__tests__/schema.test.ts`
## Common Pitfalls
- **Missing FK in delete cascade**: Adding a table with `userId.references(() => users.id)` without updating `deleteUserAccount()` — user deletion fails silently
- **Wrong delete order**: Deleting a parent before its FK children causes constraint violations
- **Non-nullable FK without onDelete**: Postgres defaults to RESTRICT, blocking parent deletion
- **Transaction atomicity**: Multi-table mutations must use `sql.transaction([...statements])` — individual statements are not atomic together
## Neon-Specific
- Use `neon-http` driver (stateless HTTP), not WebSocket driver
- Transactions: `sql.transaction([stmt1, stmt2, ...])` — array of tagged template literals
- No connection pooling needed — each request is independent
- Schema lives in `web/src/lib/db/schema.ts`, client in `web/src/lib/db/client.ts`
Files in this package (6)
- SKILL.md 4 KB
- references/neon-http-gotchas.md 4 KB
- references/transaction-patterns.md 4 KB
- scripts/migration-validate.sh 2 KB
- scripts/schema-diff.sh 2 KB
- templates/migration-template.sql 3 KB
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · Tristan578/project-forge | 100 | Apache-2.0 |
| simstudioai/sim | 100 | Apache-2.0 |
| mgiovani/cc-arsenal | 100 | MIT |
| duc01226/EasyPlatform | 96 | MIT |
| duc01226/EasyPlatform | 96 | MIT |
Identical content appears in 1 other GitHub folders. We show one copy with the highest score.
Database snapshot: 13.11.2026 · package version bd3aecddc8f6 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100drizzle-kit
Use when managing Drizzle Kit schema migrations, drizzle.config files, generate, migrate, push, introspect, check, and studio workflows. - 100drizzle-migrations
Manage database schema with Drizzle ORM and SQLite migrations. Use when adding tables, modifying columns, creating indexes, or running migrations. Activates for database schema changes, migration generation, and Drizzle query patterns. - 100neon-drizzle-stinger
Neon Postgres and Drizzle ORM on SvelteKit/Vercel: connections, schema, migrations, branching, query patterns, pgvector, RLS, and migrating off Supabase. Use for any Neon or Drizzle task. - 100data
Choose and prepare the database, ORM, object storage, and key-value store (Drizzle ORM, Cloudflare D1, R2, KV, Supabase, Neon, or another) and verify schema, migration, binding, and connection readiness locally without touching remote data. Use for /data, database setup, Drizzle… - 90database-change
Database changes with Drizzle: tables, columns, indexes, migrations and data fixes, applied locally or in production. Use for any tables.ts, migration or data change in {{db}}. - 100bun-drizzle-integration
Use when integrating Drizzle ORM with Bun's SQLite driver for type-safe schema definitions and migrations.