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.

Stars 27
Forks 4

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

bash
# 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

  1. Edit db/schema.sql
  2. Apply locally: just db-migrate
  3. Generate types: just db-schema
  4. Update any affected services/routers
  5. 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.

bash
# 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 uuid primary keys
  • Use created_at / updated_at timestamps
  • Enforce tenancy at service layer (e.g., todos.user_id)
  • Columns mapped to camelCase in TypeScript via Kysely plugin

Runtime DB Access

typescript
// 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 db dependency for testing

Gotchas

  • Tests apply db/schema.sql into testcontainers Postgres
  • After schema changes:
    • Update db/schema.sql
    • Re-apply locally (just db-migrate)
    • Re-generate TS types (just db-schema)
  • Generated types: packages/backend/core/src/schema.ts

Expand your agent's capabilities with these related and highly-rated skills.

frmlabz/frm-stack

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.

27 4
Explore
frmlabz/frm-stack

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.

27 4
Explore
frmlabz/frm-stack

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.

27 4
Explore
frmlabz/frm-stack

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.

27 4
Explore
frmlabz/frm-stack

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”.

27 4
Explore
frmlabz/frm-stack

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.

27 4
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results