migrations
Run migrations, generate schemas, and manage code generation for Momentum CMS. Use when working with database migrations, Drizzle schema generation, type generation, or Angular schematics.
Best use case
migrations is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Run migrations, generate schemas, and manage code generation for Momentum CMS. Use when working with database migrations, Drizzle schema generation, type generation, or Angular schematics.
Teams using migrations should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/migrations/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How migrations Compares
| Feature / Agent | migrations | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Run migrations, generate schemas, and manage code generation for Momentum CMS. Use when working with database migrations, Drizzle schema generation, type generation, or Angular schematics.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Migrations & Code Generation
Reference for database migrations and type/config generation in the Momentum CMS monorepo.
## Arguments
- `$ARGUMENTS` - Operation: `generate`, `run`, `status`, `rollback`, or `codegen`
## Field Builder Reference
Collections use typed field builders from `@momentumcms/core`. **Always use these builders — never define raw field objects.**
```typescript
import {
text,
textarea,
richText,
number,
date,
checkbox,
select,
radio,
email,
password,
upload,
relationship,
array,
group,
blocks,
json,
point,
slug,
tabs,
collapsible,
row,
} from '@momentumcms/core';
```
### Common Field Builders
| Builder | DB Type | Notes |
| -------------------------- | -------------- | --------------------------------------------------- |
| `text(name, opts?)` | `VARCHAR` | String field. `{ required: true }` for non-nullable |
| `textarea(name, opts?)` | `TEXT` | Long text |
| `richText(name, opts?)` | `JSONB` | Structured rich text content |
| `number(name, opts?)` | `NUMERIC` | Use `{ min, max }` for validation |
| `date(name, opts?)` | `TIMESTAMPTZ` | Date/time field |
| `checkbox(name, opts?)` | `BOOLEAN` | Boolean field — **NOT** `boolean()` |
| `select(name, opts)` | `VARCHAR` | Requires `{ options: [...] }` |
| `radio(name, opts)` | `VARCHAR` | Requires `{ options: [...] }` |
| `email(name, opts?)` | `VARCHAR` | Email with validation |
| `upload(name, opts?)` | `VARCHAR` | File upload reference |
| `relationship(name, opts)` | `VARCHAR` (FK) | `{ collection: () => Target }` |
| `slug(name, opts)` | `VARCHAR` | Auto-generated from source field |
| `json(name, opts?)` | `JSONB` | Raw JSON storage |
| `point(name, opts?)` | `POINT` | Geographic coordinates |
### Layout Fields (no DB column)
| Builder | Purpose |
| ------------------------- | -------------------------------------------- |
| `array(name, opts)` | Repeatable field groups (stored in JSONB) |
| `group(name, opts)` | Grouped fields under a namespace |
| `blocks(name, opts)` | Polymorphic content blocks (stored in JSONB) |
| `tabs(name, opts)` | Tab-based field organization |
| `collapsible(name, opts)` | Collapsible section |
| `row(name, opts)` | Horizontal layout for fields |
### Common Mistakes
- **`boolean()` does not exist** — use `checkbox()` for boolean fields
- **`string()` does not exist** — use `text()` for string fields
- Always import field builders from `@momentumcms/core`, not from sub-paths
- `relationship()` requires `collection: () => Target` (lazy reference to avoid circular imports)
- `select()` and `radio()` require an `options` array — not optional
## Collection Definition Pattern
```typescript
import {
defineCollection,
text,
richText,
number,
relationship,
allowAll,
} from '@momentumcms/core';
import { Products } from './products.collection';
export const Reviews = defineCollection({
slug: 'reviews', // Must match filename: reviews.collection.ts
labels: { singular: 'Review', plural: 'Reviews' },
fields: [
text('title', { required: true, label: 'Title' }),
richText('body', { label: 'Body' }),
number('rating', { required: true, label: 'Rating', min: 1, max: 5 }),
relationship('product', { collection: () => Products, label: 'Product' }),
],
access: {
read: allowAll(),
create: allowAll(),
update: allowAll(),
delete: allowAll(),
admin: allowAll(),
},
});
```
**Key conventions:**
- File naming: `<slug>.collection.ts` in `libs/example-config/src/collections/`
- Export the collection constant from `libs/example-config/src/collections/index.ts`
- Slug must match the filename (e.g., `slug: 'reviews'` → `reviews.collection.ts`)
- Always include `access` configuration
## Momentum Migration CLI (`@momentumcms/migrations`)
```bash
# In the monorepo (via Nx targets on example apps):
nx run example-angular:migrate:generate # Diff schema, create migration file
nx run example-angular:migrate:run # Apply pending migrations
nx run example-angular:migrate:status # Show applied vs pending
nx run example-angular:migrate:rollback # Rollback latest batch
```
**Migration files are generated in the `migrations/` directory at the project root**, not inside `apps/`.
## Code Generation (Unified Generator)
The generator reads `momentum.config.ts` (server-side, Node) and outputs:
1. **TypeScript types** — interfaces for all collections, blocks, where clauses → `apps/example-angular/src/generated/momentum.types.ts`
2. **Browser-safe admin config** — inlined collections with server-only props stripped → `apps/example-angular/src/generated/momentum.config.ts`
```bash
nx run example-angular:generate # One-shot generation
nx run example-angular:generate:watch # Watch mode
```
## Migration Config Setup
If the `migrate:generate` target is not configured, add a migrations block to `momentum.config.ts`:
```typescript
const config = defineMomentumConfig({
db: { adapter: dbAdapter },
migrations: {
directory: './migrations',
},
// ... rest of config
});
```
## Workflow
**Always follow this exact order:**
1. Make collection changes in `libs/example-config/src/collections/`
2. Export from barrel file `libs/example-config/src/collections/index.ts`
3. Run `nx run example-angular:generate` to regenerate types + admin config
4. Verify generated types at `apps/example-angular/src/generated/momentum.types.ts`
5. Run `nx run example-angular:migrate:generate` to create a migration file
6. Review the generated migration SQL in `migrations/`
7. Run `nx run example-angular:migrate:run` to apply
**Do NOT skip steps 2-3.** The type generator reads the live config — if the barrel doesn't export the new collection, it won't appear in generated types.
## Angular Schematics
Both `@momentumcms/core` and `@momentumcms/migrations` ship Angular schematics:
```bash
# Type/config generation (in scaffolded Angular projects)
ng generate @momentumcms/core:types
# Migrations (in scaffolded Angular projects)
ng generate @momentumcms/migrations:generate
ng generate @momentumcms/migrations:run
ng generate @momentumcms/migrations:status
ng generate @momentumcms/migrations:rollback
```
<!-- v1 changes:
- Added complete field builder reference table with all 21 builders from @momentumcms/core
- Added "Common Mistakes" section (boolean() doesn't exist, use checkbox())
- Added full collection definition example with conventions
- Added migration config setup instructions
- Clarified migration files go to project root migrations/ dir
- Emphasized workflow ordering with "Do NOT skip" warning
- Added generated file output paths
-->Related Skills
headless-ui
Use @momentumcms/headless inside generated Momentum apps. Use when building custom public UI, composing accessible primitives, configuring global styles for hdl-* elements, or adding app-level tests around headless interactions.
ui-audit
Comprehensive UI component audit for Momentum CMS. Use when asked to audit, review, check, or validate a UI component. Checks Storybook stories, interaction tests, variants, kitchen sink integration, admin dashboard usage, accessibility, and responsive design (mobile-first). AUTOMATICALLY FIXES issues found and verifies with visual inspection. Triggers include "audit button", "review the card component", "check accessibility of tabs", or "/ui-audit <component-name>".
test-all
Run the FULL Momentum CMS test suite — every single suite, no skips. Triggers on "test all", "test everything", "run all tests", "run the test all script", "test-all script", "run the full suite", "run every test", "test the whole thing", "make sure everything passes", "run test:all", or ANY variation asking to run all/every/full tests. Also triggers on typos like "test al", "tets all", "tes all". NEVER skip suites unless the user EXPLICITLY names suites to skip.
stroll-test
End-to-end CLI stroll test of npm-published Momentum CMS packages. Scaffolds a fresh project with create-momentum-app, adds all plugins, runs migrations, starts server, and verifies everything works. Triggers include "stroll test", "cli stroll", "test published packages", or "/stroll-test".
skill-improve
Self-improving skill loop. Analyzes eval failures, rewrites the skill, re-evaluates, and repeats until convergence. Run after /skill-eval produces baseline results.
skill-eval
Run structured evaluations comparing skill vs no-skill performance. Measures assertion pass rates, timing, and output quality to systematically improve skills.
prepare-release
Prepare a patch/minor/major version release for all Momentum CMS packages. Bumps versions, generates changelogs, verifies builds/tests, adds new packages to Nx release config, and commits. Triggers include "prepare release", "bump version", "release patch", or "/prepare-release".
momentum-api
Work with Momentum API for data operations in Angular components
mcp-setup
Set up the Momentum CMS MCP server plugin and generate Claude Code MCP config for AI tool integration. Use when connecting Claude Code (or any MCP client) to a Momentum CMS instance.
SYSTEM ROLE & BEHAVIORAL PROTOCOLS
**ROLE:** Senior Frontend Architect & Avant-Garde UI Designer.
headless-primitive
Author, extend, or repair primitives in libs/headless. Use when adding a new headless primitive, changing its accessibility contract, updating slots/state attrs, wiring overlay behavior, or expanding the example styling lab and tests.
e2e-test
Write and validate Playwright E2E tests for Momentum CMS features. UI tests ALWAYS start from /admin dashboard and navigate via sidebar/dashboard — never go directly to deep URLs. Always starts the server and inspects the actual UI before writing assertions. Triggers include "write e2e tests for...", "add e2e tests", "test the admin UI for...", or "/e2e-test <feature>".