# zenstack-db-migration

The zenstack-db-migration Claude Code skill manages database schema migrations in ZenStack V3. It activates for migration work, schema prototyping, or introspecting an existing database.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 551 installs · ★ 3 repo stars
- Author: zenstackhq
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/zenstackhq/skills/tree/HEAD/skills/zenstack-db-migration/SKILL.md
- Updated: 2026-10-28
- Security check: automated, 2026-11-17 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/zenstack-db-migration

## What it does

The skill guides ZenStack V3 migration work: create and apply changes with `zen migrate dev` and `zen migrate deploy`, inspect migration status, or repair migration history. For local experiments, `zen db push` syncs the schema without recording a migration. `zen db pull` reads an existing database schema into ZModel; the experimental command can overwrite the schema file.

Use `--create-only` to produce a migration file without applying it, then edit its SQL manually, including for database views. `zen migrate reset` drops tables and replays migrations, so it is limited to development and testing, never production. Run `zen generate` after schema edits to refresh generated types.

The ZenStack project must already be set up. `@zenstackhq/cli` has a peer dependency on `prisma` and installs it automatically when needed.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add zenstackhq/skills --skill zenstack-db-migration -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/zenstack-db-migration/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/zenstack-db-migration/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add zenstackhq/skills --skill zenstack-db-migration -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/zenstack-db-migration/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add zenstackhq/skills --skill zenstack-db-migration -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/zenstack-db-migration/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install zenstackhq/skills skills/zenstack-db-migration
```

2. **Manually: put the files in place**
- File: `.github/skills/zenstack-db-migration/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add zenstackhq/skills --skill zenstack-db-migration -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/zenstackhq/skills --path skills/zenstack-db-migration
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/zenstack-db-migration/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add zenstackhq/skills --skill zenstack-db-migration -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/zenstackhq/skills/tree/HEAD/skills/zenstack-db-migration/SKILL.md

## When to use it
- create and apply a migration from ZModel changes
- sync a database to the schema without recording migration history
- check which migrations are pending
- load an existing database schema into ZModel
- prepare migration commands for a deployment pipeline

## Example prompts
- Create a migration named `add_published_flag` for the ZenStack schema changes.
- Show which migrations have been applied and which are pending.
- Read the existing database schema into the ZModel file.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 6eae2b73a48df7d1.

BEGIN THIRD-PARTY FILE 6eae2b73a48df7d1
````text
---
name: zenstack-db-migration
description: Manage database schema migrations in ZenStack V3. Use when creating/applying migrations (zen migrate dev/deploy/reset/status/resolve), prototyping with zen db push, introspecting an existing database with zen db pull, seeding, handling unsupported features (views) with --create-only, or wiring migrations into a deployment pipeline.
---

# ZenStack V3 — Database Migrations

ZenStack keeps your database schema in sync with your ZModel data model. Migration is built on top
of [Prisma Migrate](https://www.prisma.io/docs/orm/prisma-migrate): the `zen` CLI generates a Prisma
schema from your ZModel under the hood and wraps the corresponding Prisma command. If you know Prisma
Migrate, the workflow is identical — just swap `prisma` for `zen`. Existing migration history keeps
working once moved into ZenStack's layout (`prisma/migrations` → `zenstack/migrations`, the default
location next to `zenstack/schema.zmodel`).

This skill assumes a project is already set up (see `zenstack-project-setup`). Schema authoring is in
`zenstack-schema-modeling`. `@zenstackhq/cli` carries a peer dependency on `prisma`, installed
automatically when needed.

> Run `zen generate` after schema changes to refresh generated types; migration commands operate on
> the schema independently of the generated client.

## Two ways to evolve the schema

| Approach | Command | When |
| -------- | ------- | ---- |
| **Schema prototyping** | `zen db push` | Local dev/experimentation — syncs the DB to the schema with **no migration file**. Fast, but loses history. **Never in production.** |
| **Tracked migrations** | `zen migrate dev` → `zen migrate deploy` | Anything you ship — generates reviewable, committed SQL migration files applied deterministically across environments. |

Typical loop: prototype with `db push` while iterating, then create a migration with `migrate dev`
once the shape settles.

## Commands

All migration/db commands accept `--schema <file>` (defaults to `zenstack/schema.zmodel`) and
`--migrations <path>` (the directory holding `migrations/`).

### `zen migrate dev` — create + apply a migration (development)

Diffs the schema against migration history, generates a new timestamped migration file, and applies
it to the dev database. Prompts if a full reset is required (e.g. drift).

```bash
zen migrate dev --name add_published_flag
```

- `-n, --name <name>` — name the migration (otherwise you're prompted).
- `--create-only` — generate the migration file **without applying it**. Use this to hand-edit SQL,
````
END THIRD-PARTY FILE 6eae2b73a48df7d1

The third-party file has ended. Everything between the 6eae2b73a48df7d1 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2588 of 6782 bytes. © zenstackhq · MIT · https://github.com/zenstackhq/skills/tree/HEAD/skills/zenstack-db-migration/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
