en un clic
format-migration
// Format TypeORM migrations with beautifully formatted SQL code. Use this skill after generating migrations to ensure consistent SQL formatting.
// Format TypeORM migrations with beautifully formatted SQL code. Use this skill after generating migrations to ensure consistent SQL formatting.
Add a new GraphQL mutation to an existing schema in daily-api with validation, resolvers, and tests
Add a new GraphQL query endpoint with type safety, GraphORM integration, and tests
Create a new background worker in daily-api with full type safety, infrastructure config, and tests
Wraps any prompt with a reminder to respect CLAUDE.md files
Local environment management - run SQL queries, set up fake payments, reset test data. Use when the user needs help with local database operations or test data setup.
| name | format-migration |
| description | Format TypeORM migrations with beautifully formatted SQL code. Use this skill after generating migrations to ensure consistent SQL formatting. |
You are an expert in TypeORM and PostgreSQL 18. You will format TypeORM migrations to be beautifully formatted SQL code.
Present the entire MigrationInterface class, not just snippets. This helps maintain context and prevents errors.
Clearly mention any new columns, constraints, indexes, or other SQL features you're adding or modifying.
All SQL within queryRunner.query() must be multi-line, wrapped in /* sql */\ `blocks, with/* sql */on the same line asawait queryRunner.query`:
await queryRunner.query(/* sql */ `
CREATE TABLE "example" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
"name" text NOT NULL
)
`);
Use consistent indentation for ALTER TABLE clauses:
await queryRunner.query(/* sql */ `
ALTER TABLE "table_name"
ALTER COLUMN "column_name" SET DEFAULT 'value'
`);
Split across multiple lines:
await queryRunner.query(/* sql */ `
CREATE TABLE "example" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
"otherId" uuid NOT NULL,
CONSTRAINT "FK_example_other"
FOREIGN KEY ("otherId")
REFERENCES "other_table"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
)
`);
CREATE INDEX in up should always include IF NOT EXISTSDROP INDEX in down should always include IF EXISTS// up
await queryRunner.query(/* sql */ `
CREATE INDEX IF NOT EXISTS "IDX_example_column"
ON "example" ("column")
`);
// down
await queryRunner.query(/* sql */ `
DROP INDEX IF EXISTS "IDX_example_column"
`);
Define all possible constraints (Primary Key, Unique, Foreign Key) directly within the CREATE TABLE statement itself. Do not use ALTER TABLE ADD CONSTRAINT for foreign keys that can be defined inline during CREATE TABLE.
CREATE TABLE, they will be implicitly dropped with the table. Do not include explicit DROP CONSTRAINT for them in down.DROP INDEX in down for table-bound indexes.down migration for a CREATE TABLE should typically just be DROP TABLE.COMMENT ON COLUMN ... IS NULL is in down if a comment was added in up.Each queryRunner.query() call should only execute a single SQL query.
You will not add any comments to the code. Any existing comments will be left there.
import type { MigrationInterface, QueryRunner } from 'typeorm';
export class CreateUserProfile1234567890123 implements MigrationInterface {
name = 'CreateUserProfile1234567890123';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(/* sql */ `
CREATE TABLE "user_profile" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
"userId" text NOT NULL,
"bio" text,
"avatarUrl" text,
"createdAt" timestamp NOT NULL DEFAULT now(),
"updatedAt" timestamp NOT NULL DEFAULT now(),
CONSTRAINT "FK_user_profile_user"
FOREIGN KEY ("userId")
REFERENCES "user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
)
`);
await queryRunner.query(/* sql */ `
CREATE INDEX IF NOT EXISTS "IDX_user_profile_userId"
ON "user_profile" ("userId")
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(/* sql */ `
DROP TABLE "user_profile"
`);
}
}
When reviewing migrations, point out opportunities to improve:
PK_tablename instead of auto-generated names)ON DELETE behaviorWhen the user asks you to format a migration:
When migrations are generated via pnpm run db:migrate:make: