// Schema for the {{projectName}} backend. // // Tables are auto-discovered: every exported `table(...)` in this file // (or any `*.entity.ts` / `*.schema.ts` file) is registered by // `voltro dev` — no manual barrel. `actors` + `tenants` are the // framework's core tables: the built-in `audit()` / `tenant()` / // `softDelete()` mixins reference them, so they must be declared (the // CLI wires them into the mixin registry once it finds them). // // Add the `tenant()` mixin to a table to make it tenant-scoped — the // runtime AND-merges `eq('tenantId', subject.tenantId)` into every // subscription predicate, so cross-tenant reads can't leak. import { boolean, databaseHandle, id, table, text, timestamp, type InferRow, } from '@voltro/database' import { tenant } from '@voltro/plugin-multitenancy' // ---------- Core tables (required by the audit / tenant mixins) ---------- export const actors = table('actors', { id: id(), kind: text().oneOf(['user', 'serviceAccount', 'apiKey', 'system']), displayName: text().nullable(), createdAt: timestamp().default('now'), }) export const tenants = table('tenants', { id: id(), name: text(), createdAt: timestamp().default('now'), }) // ---------- Application tables — rename / replace with your own ---------- export const notes = table('notes', { id: id({ prefix: 'note' }), title: text(), body: text(), done: boolean().default(false), }) // tenant() pulls audit() transitively → adds tenantId + createdAt / // updatedAt / createdBy / updatedBy (auto-stamped by the runtime). .with(tenant()) export type Note = InferRow export const database = databaseHandle({ actors, tenants, notes })