You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-3.x/migrate-v2.md
+38-2Lines changed: 38 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,9 +40,11 @@ Here are a few essential items to verify before preparing your migration:
40
40
41
41
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.
42
42
43
-
## Migrating Access Policies
43
+
## Migrating ZModel
44
44
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.
46
48
47
49
1. Install the package
48
50
@@ -115,6 +117,40 @@ model Post {
115
117
}
116
118
```
117
119
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
+
118
154
## Migrating Server Adapters
119
155
120
156
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