Agent skill
db-workflow
Database workflow with Postgres, Kysely, and Atlas migrations. Use when modifying database schema, creating migrations, generating TypeScript types, or troubleshooting database issues. Triggers on "schema change", "migration", "db-migrate", "kysely", "atlas", or when editing db/schema.sql.
Install this agent skill to your Project
npx add-skill https://github.com/frmlabz/frm-stack/tree/main/capabilities/backend/skills/db-workflow
SKILL.md
Database Workflow
Source of truth: db/schema.sql is the canonical schema.
Quick Commands
| Command | Purpose |
|---|---|
just db-migrate |
Apply schema directly (fast iteration) |
just db-migration-new <name> |
Create versioned migration |
just db-migration-apply |
Apply versioned migrations |
just db-migration-status |
Check migration status |
just db-schema |
Generate TypeScript types |
Workflow Decision Tree
Schema change needed?
├─ Early development / experimenting
│ └─ Edit db/schema.sql → just db-migrate → just db-schema
│
└─ Production / reviewable history needed
└─ Edit db/schema.sql → just db-migration-new <name> → just db-migration-apply → just db-schema
Local Dev Setup
# 1. Start Postgres
docker compose up -d # or: just setup
# 2. Apply schema
just db-migrate
# 3. Generate TypeScript types (after schema changes)
just db-schema
Schema Changes Checklist
- Edit
db/schema.sql - Apply locally:
just db-migrate - Generate types:
just db-schema - Update any affected services/routers
- Run tests:
pnpm test
Versioned Migrations (Atlas)
Even with versioned migrations, db/schema.sql stays the source of truth. Atlas uses it to infer changes.
# Create migration from schema diff
just db-migration-new add_user_roles
# Apply migrations
just db-migration-apply
# Check status
just db-migration-status
Conventions
- Use
uuidprimary keys - Use
created_at/updated_attimestamps - Enforce tenancy at service layer (e.g.,
todos.user_id) - Columns mapped to camelCase in TypeScript via Kysely plugin
Runtime DB Access
// packages/backend/core/src/db.ts
import { connectDB, getDB } from "@yourcompany/backend-core/db";
// At app startup (once)
await connectDB({ connectionString: config.DATABASE_URL });
// Anywhere after initialization
const db = getDB();
const users = await db.selectFrom("user").selectAll().execute();
Why Kysely (vs Drizzle/Prisma)
- Typed query builder without ORM "model" layer
- Works with SQL-first workflow (
db/schema.sql) + codegen - Easy to pass
dbdependency for testing
Gotchas
- Tests apply
db/schema.sqlinto testcontainers Postgres - After schema changes:
- Update
db/schema.sql - Re-apply locally (
just db-migrate) - Re-generate TS types (
just db-schema)
- Update
- Generated types:
packages/backend/core/src/schema.ts
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
testing
Shared database testing patterns with testcontainers and Vitest. Use when writing backend tests, setting up test files, debugging test failures, or configuring Vitest. Triggers on "write tests", "test setup", "testcontainers", "vitest config", "test isolation", or when creating new test suites.
mobile-auth
Better Auth integration with Expo/React Native. Use when working on mobile authentication, session management, or debugging auth issues in the mobile app. Triggers on "mobile auth", "expo auth", "better-auth expo", "session provider", "SecureStore", or when editing apps/frontend/mobile auth files.
react-useeffect
React useEffect best practices from official docs. Use when writing/reviewing useEffect, useState for derived values, data fetching, or state synchronization. Teaches when NOT to use Effect and better alternatives.
frontend-design
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.
resolve-pr-comments
Address GitHub PR review comments end-to-end, fetch unresolved review threads (via `gh` GraphQL), implement fixes, reply with what changed, and resolve threads using the bundled scripts. Use when asked to “address PR comments”, “resolve review threads”, or “clear requested changes”.
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.
Didn't find tool you were looking for?