Database Reference
Overview of the database schema and data model
Database & Multi-Tenant Architecture
Canvas Forge uses PostgreSQL with Drizzle ORM. All database access goes through
@repo/database; application code must not instantiate a separate Drizzle or Neon
client.
Multi-tenant isolation
Tenant-owned operational tables generally carry a teamId column. This is a local
Canvas Forge tenant identifier named by CANVAS_TEAM_ID, not a Clerk Organization ID.
Global, reference, audit, migration, and system-owned tables follow their explicit
schema and ownership contracts rather than a universal tenant-column rule.
- Every tenant-owned read and write must enforce the authorized tenant and, where applicable,
locationIdscope. - Clerk authenticates the user; authentication alone is not authorization. Server actions and API routes resolve and verify local team/location ownership before querying or mutating.
- Runtime, migration, serving-reader, and audit-reader database identities remain separate and least-privileged.
Schema management
Schema changes use generated Drizzle migrations. Review the SQL and journal, rehearse on a disposable or production-derived branch as appropriate, and use the repository-owned protected workflow for production. Never use a schema push, edit the migration journal, or apply migration SQL manually to production.
See the database migrations how-to for local, rehearsal, and production command contracts. The database access workflow owns migration invariants.
Seed data
Seed commands and local fixture ownership are maintained in SETUP.md and the CLI command reference. Seeds are for disposable/local targets only; they are not a production migration path.