# Db Migration

> Make a database schema change safely — edit schema.ts, generate the migration, review the SQL, apply it. Use for any change under src/db/.

- **Type:** Skill
- **Install:** `agentstack add skill-nikandr-surkov-ai-saas-starter-db-migration`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [nikandr-surkov](https://agentstack.voostack.com/s/nikandr-surkov)
- **Installs:** 0
- **Category:** [Databases](https://agentstack.voostack.com/c/databases)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [nikandr-surkov](https://github.com/nikandr-surkov)
- **Source:** https://github.com/nikandr-surkov/ai-saas-starter/tree/main/.claude/skills/db-migration
- **Website:** https://ai-saas-starter-six.vercel.app

## Install

```sh
agentstack add skill-nikandr-surkov-ai-saas-starter-db-migration
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Database migration

Applied migrations are immutable history. This skill exists so nobody ever
"just edits the SQL file".

## Steps

1. **Ask the user first.** Schema changes are on the ASK FIRST list in
   AGENTS.md. Describe the change and why.
2. Edit `src/db/schema.ts` only. Conventions:
   - Every foreign key gets an index.
   - Timestamps: `createdAt` with `defaultNow()`, timezone-aware.
   - Money in integer cents; credits in integers.
   - Enums via `pgEnum`, named `_`.
3. Generate: `pnpm db:generate`. Never write migration SQL by hand.
4. **Read the generated file in `drizzle/`.** Confirm: no unintended
   `DROP`, correct column types/defaults, indexes present. Column renames
   often generate drop+create — if data must survive, say so and write the
   migration plan out for the user before applying.
5. Apply locally: `pnpm db:migrate` (Postgres running via
   `docker compose up -d`).
6. Run `pnpm test` — the ledger suite will catch schema drift in credit
   tables.
7. Commit `src/db/schema.ts` and the new `drizzle/` files together.

## Never

- Edit or delete an existing file in `drizzle/`.
- Run `drizzle-kit push` against anything but a throwaway local DB —
  this repo uses generated, committed migrations.
- Touch `credit_transactions` semantics (signed integer amounts, UNIQUE
  `idempotencyKey`) without reading `.claude/rules/billing.md`.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [nikandr-surkov](https://github.com/nikandr-surkov)
- **Source:** [nikandr-surkov/ai-saas-starter](https://github.com/nikandr-surkov/ai-saas-starter)
- **License:** MIT
- **Homepage:** https://ai-saas-starter-six.vercel.app

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-nikandr-surkov-ai-saas-starter-db-migration
- Seller: https://agentstack.voostack.com/s/nikandr-surkov
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
