agentleFS
aiqadamaiqadam/qadam-flow/.agents/skills/db-migration/SKILL.md

db-migration

Skill4 starsChanged 2 months agoMITView on GitHub

Creates TypeORM database migrations for the Qadam Flow server. Use when the user asks to add a column, create a table, add an index, or make any schema change to the database.

6 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 3 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Create TypeORM database migrations for schema changes in the Qadam Flow server API.

    line 8
  2. Very specific:

    Update the TypeORM entity file in packages/server/api/src/app/ to reflect the new schema.

    line 22
  3. Very specific:

    Add breaking = false (or true if destructive)

    line 48
  4. Very specific:

    Add release = '<version>' matching the upcoming release version from root package.json

    line 49
  5. Very specific:

    Verify down() correctly reverses up()

    line 50
  6. Distinctive:

    After the migration is generated and registered, update any TypeScript types, service files, or other code that references the changed …

    line 107
  7. Distinctive:

    Always try to create non-breaking migrations if possible to allow safe rollbacks

    line 111

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Qadam Flow DB Migration

Create TypeORM database migrations for schema changes in the Qadam Flow server API.

Workflow

Step 1: DETERMINE THE CHANGE

Before generating, identify:

  • Which table(s) are affected
  • What SQL is needed (ADD COLUMN, CREATE TABLE, CREATE INDEX, etc.)
  • Whether the migration is breaking (drops columns/tables, transforms data irreversibly — cannot be rolled back safely)
  • The current release version (check root package.json → version)

Step 2: UPDATE THE ENTITY

Update the TypeORM entity file in packages/server/api/src/app/ to reflect the new schema. This ensures the CLI generation command can diff against the current state.

Array columns always use this pattern:

columnName: {
    type: String,
    array: true,
    nullable: false,
}

Step 3: GENERATE THE MIGRATION USING THE CLI

Run from packages/server/api/:

npm run db-migration -- src/app/database/migration/postgres/MigrationName

This diffs the current entity state against the database and generates the migration file with correct SQL and timestamp.

Step 4: PATCH THE GENERATED FILE

The CLI generates a file using MigrationInterface. You must patch it to use the project's Migration interface and add required fields:

  1. Replace import { MigrationInterface, QueryRunner } from "typeorm" with import { QueryRunner } from 'typeorm' and add import { Migration } from '../../migration'
  2. Replace implements MigrationInterface with implements Migration
  3. Add breaking = false (or true if destructive)
  4. Add release = '<version>' matching the upcoming release version from root package.json
  5. Verify down() correctly reverses up()

Example result:

import { QueryRunner } from 'typeorm'
import { Migration } from '../../migration'

export class AddMyColumn1234567890 implements Migration {
    name = 'AddMyColumn1234567890'
    breaking = false 
    release = '0.78.0'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "project" ADD COLUMN "description" text`)
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "project" DROP COLUMN "description"`)
    }
}

Required fields:

  • name = '<ExportedClassName>' — the CLI sets this; do not blank it out
  • breaking = false — set to true only if rolling back is destructive
  • release = '<version>' — the upcoming release version from root package.json
  • down() — must reverse up() (required)

The Migration type marks breaking/release optional, but _verify.yml's "Check new migration metadata" step (part of the required Lint + Unit Tests check, not a separate context of its own) runs tools/scripts/check-migration-rollback.ts (npm run check-migration-metadata) on every PR (#445): a new migration missing name, breaking, an invalid/missing release, or missing down() fails the build and names the field. down() missing is actually caught earlier still, at compile time — typeorm's MigrationInterface.down is non-optional. name matters beyond the gate too: rollback-migrations.ts keys manifest-based rollback on it, so a blank or mismatched one silently drops the migration from that path instead of failing loudly — the gate also checks it matches the exported class name. Set all four anyway; do not rely on the gate to catch it.

Step 5: REGISTER THE MIGRATION

Open packages/server/api/src/app/database/postgres-connection.ts and add the new migration class to the getMigrations() array (at the end, in chronological order):

import { AddMyColumn1234567890 } from './migration/postgres/1234567890-AddMyColumn'

// Inside getMigrations():
return [
    // ... existing migrations ...
    AddMyColumn1234567890,
]

Step 6: UPDATE TYPES AND SERVICE CODE

After the migration is generated and registered, update any TypeScript types, service files, or other code that references the changed columns to stay in sync with the new schema.

Note:

Always try to create non-breaking migrations if possible to allow safe rollbacks

Zero errors required before the task is complete.


Using CONCURRENTLY

Qadam Flow runs against real PostgreSQL only (PGLite support was removed). When creating or dropping indexes with CONCURRENTLY, set transaction = false on the migration — PostgreSQL requires it, since CONCURRENTLY cannot run inside a transaction:

import { QueryRunner } from 'typeorm'
import { Migration } from '../../migration'

export class AddMyIndex1234567890 implements Migration {
    name = 'AddMyIndex1234567890'
    breaking = false
    release = '0.78.0'
    transaction = false  // Required when using CONCURRENTLY

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE INDEX CONCURRENTLY "idx_name" ON "table" ("column")`)
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`DROP INDEX CONCURRENTLY "idx_name"`)
    }
}

Quick Reference

FieldValue
Migration filespackages/server/api/src/app/database/migration/postgres/
Registrationpackages/server/api/src/app/database/postgres-connection.ts
Migration importimport { Migration } from '../../migration'
Generate commandnpm run db-migration -- src/app/database/migration/postgres/MigrationName (run from packages/server/api/)

Critical Reminders

  1. Always generate via CLI — never write migration SQL by hand; use npm run db-migration to generate from the entity diff
  2. Never use MigrationInterface — always patch the generated file to use Migration from ../../migration
  3. name, breaking, release, and down() are mandatory — set them explicitly; a required CI check (npm run check-migration-metadata) rejects a new migration that omits one
  4. Register in postgres-connection.ts — migration won't run without this
  5. CONCURRENTLY — always set transaction = false when using it

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.