Skip to main content

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:

  1. Open the models.zmodel file in your project.
  2. 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:

  1. Locate the model in your models.zmodel file.
  2. 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:

  1. 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.

  1. 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.