Files
metabuilder/.github/prompts/implement/backend/3-impl-migration.prompt.md
2026-01-03 20:17:49 +00:00

966 B

Add Database Migration

Add or modify database schema:

Run app commands from frontends/nextjs/ unless a step says otherwise.

1. Update Schema

Edit prisma/schema.prisma:

model NewEntity {
  id        String  @id @default(cuid())
  name      String
  tenantId  String  // Required for multi-tenancy
  tenant    Tenant  @relation(fields: [tenantId], references: [id])
  createdAt BigInt
}

2. Generate & Apply

npm run db:generate      # Update Prisma client
npm run db:push          # Push to dev database
# OR for production:
npx prisma migrate dev --name describe_change
npm run db:migrate       # Apply in production

3. Add Database Wrapper Methods

In src/lib/database.ts:

static async getNewEntities(filter: { tenantId: string }) {
  return prisma.newEntity.findMany({
    where: { tenantId: filter.tenantId }
  })
}

4. Update DBAL (if applicable)

Add entity to dbal/shared/api/schema/entities/