Agent Skills: setup-drizzle-migration

Create DB schema changes with migration generation. Use for new tables or relations.

UncategorizedID: Oungseik/gakom/setup-drizzle-migration

Install this agent skill to your local

pnpm dlx add-skill https://github.com/MonDevHub/gakom/tree/HEAD/.claude/skills/setup-drizzle-migration

Skill Files

Browse the full folder contents for setup-drizzle-migration.

Download Skill

Loading file tree…

.claude/skills/setup-drizzle-migration/SKILL.md

Skill Metadata

Name
setup-drizzle-migration
Description
Create DB schema changes with migration generation. Use for new tables or relations.

Define new Drizzle schema and generate PostgreSQL migration.

Current Database Status

  • Existing tables: !grep -r "pgTable" --include="*.ts" packages/db/src/ | wc -l defined
  • Database URL: !echo "DATABASE_URL configured: $(grep -q DATABASE_URL .env* && echo 'YES' || echo 'NO')"
  • Migrations count: !ls packages/db/migrations/ 2>/dev/null | wc -l 2>/dev/null || echo "0"

Create:

  • Update @repo/db/schema.ts with new table/relations
  • Run drizzle-kit generate to create migration file
  • Commit migration to repository

Schema Generation Steps

  1. Define table with $ARGUMENTS columns
  2. Add relations for foreign keys if needed
  3. Include Zod validation schemas
  4. Export types from schema file

Schema conventions:

  • Use camelCase for column names (maps to snake_case in DB)
  • Define relations for foreign keys with relations()
  • Include Zod schemas for type safety alongside Drizzle schemas
  • Use PostgreSQL types with Drizzle enums where needed
  • Add indexes for frequently queried columns

Example Generated Schema

export const users = pgTable('users', {
    id: serial('id').primaryKey(),
    name: varchar('name', { length: 256 }).notNull(),
    email: varchar('email', { length: 256 }).notNull().unique(),
    createdAt: timestamp('created_at').defaultNow(),
});

// Zod schema for validation
export const insertUserSchema = createInsertSchema(users);
export const selectUserSchema = createSelectSchema(users);

Migration Testing

After generation, test migration with:

pnpm db:push  # Apply to dev DB
pnpm db:studio  # Verify in Drizzle Studio