Add Database Table
When the user invokes /add-db-table, follow these steps:
- •
Ask for the entity name and columns needed.
- •
Create schema at
apps/db/src/schema/dimensions/[entity].ts:- •Table name:
dim_[entity] - •Primary key:
uuid('id').primaryKey().defaultRandom().notNull() - •Required timestamps:
createdAt(defaultNow, notNull),updatedAt(defaultNow, notNull),deletedAt(nullable) - •Add indexes with naming pattern
dim_[entity]_[field]_idx - •Export the table and inferred types
- •Table name:
- •
Export from
apps/db/src/schema/index.ts- add to the schema registry. - •
Generate migration: Run
pnpm --filter=db db:generate - •
Review the generated migration in
apps/db/migrations/and show it to the user. - •
Run migration (with user confirmation):
pnpm --filter=db db:migrate - •
Verify: Run
pnpm typecheckto confirm no type errors.