// 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). // // `orders` carries the `tenant()` mixin (→ tenantId + audit columns, // auto-stamped by the runtime) and `.reactive()` so the `orderChanges` // subscriber + any live subscription wake on every write. import { databaseHandle, id, integer, 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 table — order-fulfillment domain ---------- export const orders = table('orders', { id: id({ prefix: 'order' }), // The fulfillment lifecycle. `oneOf` narrows the row type to the // literal union AND emits a cross-dialect CHECK constraint. status: text().oneOf([ 'placed', // created, fulfillment workflow kicked off 'reserved', // stock reserved (workflow step 1) 'approved', // human approval signal accepted 'rejected', // human approval signal rejected 'shipped', // shipped (workflow final step) ]).default('placed'), customerName: text(), amountCents: integer(), }) // tenant() pulls audit() transitively → adds tenantId + createdAt / // updatedAt / createdBy / updatedBy (auto-stamped by the runtime). .with(tenant()) export type Order = InferRow export const database = databaseHandle({ actors, tenants, orders })