Skip to main content

Adding a database entity

  1. Add the model to the schema file for its domain (prisma/schema/NN-name.prisma), not a new single-file schema.
  2. Use UUID v7 if the model matches the operational tables: @default(uuid(7)).
  3. If the row is tenant-owned, include tenantId and @@unique([id, tenantId]) so child relations can carry the tenant. Point foreign keys at the composite where existing models do.
  4. Add deletedAt if the aggregate follows the soft-delete rule, and filter deletedAt: null in queries.
  5. Classify the model in tenancy.extension.ts as direct, indirect, or global. Global is rare. The current global set is IntegrationRegistry, Permission, PlatformRolePermission, Currency, FxRate.
  6. Create the migration. See Adding a migration.
  7. If a status field has legal edges, add a TypeScript map next to the service. Do not rely on a header comment. The order files show why.
  8. Extend the architecture test’s expectation if it enumerates models.

Raw SQL you add later must repeat tenantId. The extension will not inject it into $queryRaw.