Skip to content

Commit 09bf784

Browse files
committed
update
1 parent d5ec821 commit 09bf784

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

versioned_docs/version-3.x/migrate-v2.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ Here are a few essential items to verify before preparing your migration:
4040

4141
Since ZenStack v3 is no longer based on Prisma ORM, the first step is to replace Prisma dependencies with ZenStack and update the code where `PrismaClient` is created. Please follow the [Prisma Migration Guide](./migrate-prisma.md) for detailed instructions.
4242

43-
## Migrating Access Policies
43+
## Migrating ZModel
4444

45-
Since v3's ZModel language is backward compatible with v2, not much work is required in ZModel files. One necessary change is that, if you use access policies (`@@allow``@@deny`, etc.), they are now declared in self-contained plugins. You need to install the package separately, add a plugin declaration in ZModel, and then install the plugin at runtime.
45+
### Access Control
46+
47+
Access control functionality has been moved into a self-contained plugin. You need to install the package package, add a plugin declaration in ZModel, and then use the plugin at runtime.
4648

4749
1. Install the package
4850

@@ -115,6 +117,40 @@ model Post {
115117
}
116118
```
117119

120+
### Abstract Base Models
121+
122+
V2 had the concept of [Abstract Model](/docs/guides/multiple-schema#abstract-model-inheritance) that allows you to define base models that serve purely as base types, but are not mapped to the database. You can use the `extends` keyword to inherit from an abstract model. We found this to be confusing because `extends` is also used for inheriting from a [Polymorphic Model](/guides/polymorphism). The same keyword was used for two very different concepts.
123+
124+
In v3, abstract models are replaced with "types", and the concept of "abstract inheritance" is replaced with [Mixins](./modeling/mixin.md). What you need to do is to change `abstract model` to `type`, and change the `extends` keyword to `with`.
125+
126+
V2:
127+
128+
```zmodel
129+
abstract model Timestamped {
130+
createdAt DateTime @default(now())
131+
updatedAt DateTime @updatedAt
132+
}
133+
134+
model Post extends Timestamped {
135+
id Int @id @default(autoincrement())
136+
title String
137+
}
138+
```
139+
140+
V3:
141+
142+
```zmodel
143+
type Timestamped {
144+
createdAt DateTime @default(now())
145+
updatedAt DateTime @updatedAt
146+
}
147+
148+
model Post with Timestamped {
149+
id Int @id @default(autoincrement())
150+
title String
151+
}
152+
```
153+
118154
## Migrating Server Adapters
119155

120156
Server adapters are mostly backward compatible. One small change needed is that, when creating a server adapter, it's now mandatory to explicitly pass in an API handler instance (RPC or RESTful). The API handlers are now created with the `schema` object as input. See [Server Adapters](./service/server-adapter.md) for more details.

0 commit comments

Comments
 (0)