Update data model
This documentation explains how to update your data model and apply changes to your application using ZenStack, a superset of Prisma.
Adding a new model
To add a new model to your application:
- Open the
models.zmodel
file in your project. - Define your new model using ZenStack schema syntax. For example:
model NewModel {
id Int @id @default(uuid())
name String
dateCreated DateTime @default(now())
}
Editing a model property
To edit a property of an existing model:
- Locate the model in your
models.zmodel
file. - Modify the property as needed. For example, changing a field type or adding a new field:
model ExistingModel {
id Int @id @default(uuid())
name String
age Int // New field
email String @unique // Modified to be unique
}
Applying changes
After modifying your data model, you need to apply these changes to your API and database:
- Run the following command to update your API logic:
pnpm run crud:sync
This command will automatically generate and update the necessary API endpoints based on your model changes.
- Apply the changes to your actual database by running:
pnpm run database:sync
This command will update your database schema to match your ZenStack schema.
Automatic updates in workspace
When using the workspace, a popup will appear automatically as soon as you edit your models in the models.zmodel
file. This popup allows you to run both pnpm run crud:sync
and pnpm run database:sync
commands with a single click, streamlining the process of applying your model changes.