Execute the proper Drizzle Kit workflow for database schema migrations in asset-forge.
This skill guides you through the proper database migration workflow using Drizzle Kit for the asset-forge project.
Use this skill when:
server/db/schema/ have been modifiedAfter making changes to TypeScript schema files in packages/asset-forge/server/db/schema/, generate a migration:
cd ${WORKSPACE_DIR}/packages/asset-forge
bun run db:generate
What this does:
server/db/schema/server/db/migrations/0001_clever_name.sqlCommon errors:
/check-typesALWAYS review the SQL before applying! Use the Read tool to check:
# Find latest migration
cd ${WORKSPACE_DIR}/packages/asset-forge
ls -t server/db/migrations/*.sql | head -1
Review checklist:
After reviewing, apply the migration:
cd ${WORKSPACE_DIR}/packages/asset-forge
bun run db:migrate
What this does:
Troubleshooting:
After successful migration, verify with Drizzle Studio:
cd ${WORKSPACE_DIR}/packages/asset-forge
bun run db:studio
Opens web UI at http://test-db-studio:4983 to inspect:
After generating and applying migrations:
bun run db:push to sync schema directly (skips migrations)Drizzle Kit doesn't have automatic rollback. To rollback:
Required in .env:
DATABASE_URL="postgresql://user:pass@host:port/dbname"
# or for SQLite:
DATABASE_URL="file:./local.db"
/migrate - Full migration workflow (generate → review → apply)/migrate generate - Generate only/migrate apply - Apply only/db/studio - Launch Drizzle Studio/check-types - Verify schema TypeScript// 1. User modifies schema
// packages/asset-forge/server/db/schema/teams.schema.ts
export const teams = pgTable('teams', {
id: uuid('id').primaryKey().defaultRandom(),
name: varchar('name', { length: 255 }).notNull(),
// NEW: added description field
description: text('description'),
createdAt: timestamp('created_at').defaultNow().notNull(),
});
// 2. Generate migration
// bun run db:generate
// → Creates: 0004_amazing_hulk.sql
// 3. Review SQL
// ALTER TABLE "teams" ADD COLUMN "description" text;
// 4. Apply migration
// bun run db:migrate
// → Migration applied successfully
// 5. Commit changes
// git add server/db/schema/teams.schema.ts
// git add server/db/migrations/0004_amazing_hulk.sql
// git commit -m "feat: add description field to teams table"
packages/asset-forge/drizzle.config.ts - Drizzle Kit configurationpackages/asset-forge/server/db/schema/ - All schema definitionspackages/asset-forge/server/db/migrations/ - Generated SQL migrationspackages/asset-forge/server/db/migrations/meta/_journal.json - Migration trackingRemember: Never skip the review step! Always inspect the generated SQL before running db:migrate.