Handle Drizzle database schema changes safely. Generate and apply migrations, add tables and columns. Use when modifying database schema, adding tables, creating migrations, or making database changes.
Safely modify PostgreSQL schema using Drizzle ORM.
| File | Purpose |
|---|---|
packages/db/src/schema.ts | Main schema exports |
packages/db/src/auth-schema.ts | Better Auth tables |
packages/db/src/rag-schema.ts | RAG embeddings tables |
packages/db/drizzle/ | Generated migrations |
Read the schema file to understand existing tables:
Read: packages/db/src/schema.ts
Before making changes, confirm with user:
Edit the appropriate schema file:
// packages/db/src/schema.ts
import { pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core';
export const newTable = pgTable('new_table', {
id: uuid('id').primaryKey().defaultRandom(),
name: text('name').notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
Run migration generator:
pnpm -C packages/db migrate:generate
Read the generated migration in packages/db/drizzle/ and verify:
pnpm -C packages/db migrate:apply
pnpm typecheck
pnpm lint