Skip to content

How to Add a Database Model

Nexical uses an Additive Schema approach. You define models within your module, and the system merges them into the global schema.

Create or edit models.yaml in your module root.

modules/project/models.yaml
models:
Project:
fields:
id:
type: String
attributes:
- '@id'
- '@default(cuid())'
name:
type: String
ownerId:
type: String
# Define relations
tasks:
type: Task[]
Task:
fields:
id: { type: String, attributes: ['@id', '@default(cuid())'] }
title: { type: String }
projectId: { type: String }
project:
type: Project
attributes: ['@relation(fields: [projectId], references: [id])']

Run the database compiler to check for errors and generate the Prisma Client.

Terminal window
nexical db:generate

Create a SQL migration file for the new changes.

Terminal window
npx prisma migrate dev --name add_projects

Access the new model via the global db client.

import { db } from '@/lib/core/db';
await db.project.create({
data: { name: 'My New Project' },
});