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
+24-20Lines changed: 24 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
description: How to migrate from a ZenStack v2 project to v3
3
-
sidebar_position: 10
3
+
sidebar_position: 11
4
4
---
5
5
6
6
import PackageInstall from './_components/PackageInstall';
@@ -9,40 +9,40 @@ import PackageInstall from './_components/PackageInstall';
9
9
10
10
## Overview
11
11
12
-
ZenStack v3 is a major rewrite of v2, with a focus on simplicity and flexibility. It replaced Prisma ORM with its own ORM component built above [Kysely](https://kysely.dev/), resulting in a much more light-weighted architecture and the level extensibility that we couldn't achieve in v2.
12
+
ZenStack v3 is a major rewrite of v2, with a focus on simplicity and flexibility. It replaced Prisma ORM with its own ORM component built on top of [Kysely](https://kysely.dev/), resulting in a much more lighter-weight architecture and the level of extensibility that we couldn't achieve in v2.
13
13
14
14
A few v3 design decisions should make an upgrade much less painful:
15
15
16
-
- The ZModel schema is essentially compatible with v2.
17
-
- The ORM query API compatible with that of `PrismaClient`, thus compatible with v2.
16
+
- The ZModel schema is compatible with v2.
17
+
- The ORM query API is compatible with that of `PrismaClient`, thus compatible with v2.
18
18
19
19
However, given the architectural changes, some effort is required to adapt to the new system. This guide will help you migrate an existing ZenStack v2 project.
20
20
21
21
## Compatibility Check
22
22
23
-
Here are a few important items to verify before preparing your migration:
23
+
Here are a few essential items to verify before preparing your migration:
24
24
25
25
- Database support
26
26
27
-
V3 only supports PostgreSQL and SQLite databases for now. MySQL will be added later.
27
+
V3 currently only supports PostgreSQL and SQLite databases. MySQL will be added later.
28
28
29
-
For PostgreSQL, only native the traditional TCP-based connection is supported. Newer HTTP-based protocols like supported by newer providers like Neon and Prisma PG are not supported yet, but will be in the future.
29
+
For PostgreSQL, only native the traditional TCP-based connection is supported. Newer HTTP-based protocols, such as those supported by providers like Neon and Prisma PG, are not yet supported, but will be in the future.
30
30
31
31
- Prisma feature gaps
32
32
33
33
A few Prisma ORM's features are not implemented or not planned. Please check the [Prisma Feature Gaps](./migrate-prisma.md#feature-gaps) for details.
34
34
35
35
- V2 feature gaps
36
36
37
-
A few ZenStack v2's features are not implemented. Some less popular features are planned to be dropped. Please check the [Feature Gaps](#feature-gaps) for details.
37
+
A few ZenStack v2 features are not implemented. Some less popular features are planned to be removed. Please check the [Feature Gaps](#feature-gaps) for details.
38
38
39
39
## Migrating Prisma
40
40
41
-
Since ZenStack v3 is not based on Prisma ORM anymore, the first thing to do is to replace Prisma dependencies with ZenStack and update code where`PrismaClient`is created. Please follow the [Prisma Migration Guide](./migrate-prisma.md) for detailed instructions.
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
43
## Migrating Access Policies
44
44
45
-
Since v3's ZModel language is backward compatible with v2, no much work is needed in ZModel files. One change necessary is that, if you use access policies (`@@allow`,`@@deny`, etc.), they are now in self-contained plugins, and you need to install the package separately, add a plugin declaration in ZModel, and install the plugin at runtime.
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.
46
46
47
47
1. Install the package
48
48
@@ -86,7 +86,7 @@ async function processRequest(request: Request) {
86
86
}
87
87
```
88
88
89
-
The policy rules in ZModel are mostly backward compatible, except for a breaking change about post-update policies. In v3, post-update rules are expressed with its own "post-update" policy type and separate from regular "update" rules. Inside "post-update" rules, by default fields refer to the entity's "after-update" state, and you can use the `before()` function to refer to the "before-update" state. See [Post Update Rules](./orm/access-control/post-update.md) for more details.
89
+
The policy rules in ZModel are mostly backward compatible, except for a breaking change about post-update policies. In v3, post-update rules are expressed with their own "post-update" policy type and separate from regular "update" rules. Inside "post-update" rules, by default, fields refer to the entity's "after-update" state, and you can use the `before()` function to refer to the "before-update" state. See [Post Update Rules](./orm/access-control/post-update.md) for more details.
90
90
91
91
Here's a quick example for how to migrate:
92
92
@@ -144,9 +144,9 @@ function getClientForRequest(request: Request) {
144
144
145
145
## Migrating Client-Side Hooks
146
146
147
-
V3 brings a new implementation of [TanStack Query](https://tanstack.com/query) implementation that doesn't require code generation. Instead, TS types are fully inferred from the schema type at compile time, and the runtime logic is based on interpretation of the schema object. As a result, the new integration becomes a simple library that you call, and no plugin is involved.
147
+
V3 introduces a new implementation of [TanStack Query](https://tanstack.com/query) implementation that doesn't require code generation. Instead, TS types are fully inferred from the schema type at compile time, and the runtime logic is based on the interpretation of the schema object. As a result, the new integration becomes a simple library that you call, and no plugin is involved.
148
148
149
-
To support such an architecture change. Query hooks are now grouped into an object that mirrors the API style of the ORM client. You need to adjust v2 code (that uses the flat `useFindMany[Model]` style hooks) into this new structure.
149
+
To support such an architecture change. Query hooks are now grouped into an object that mirrors the API style of the ORM client. You need to adjust the v2 code (that uses the flat `useFindMany[Model]` style hooks) into this new structure.
150
150
151
151
V2:
152
152
```ts
@@ -174,37 +174,41 @@ export function MyComponent() {
174
174
175
175
## Migration Custom Plugins
176
176
177
-
V3 comes with a completely revised plugin system that offers great power and flexibility. You can check the concepts in the [Data Model Plugin](./modeling/plugin.md) and [ORM Plugin](./orm/plugins/) documentation.
177
+
V3 comes with a completely revised plugin system that offers greater power and flexibility. You can check the concepts in the [Data Model Plugin](./modeling/plugin.md) and [ORM Plugin](./orm/plugins/) documentation.
178
178
179
179
The plugin development document is still WIP. This part of the migration guide will be added later when it's ready.
180
180
181
181
## Feature Gaps
182
182
183
-
This section lists v2 features that haven't been migrated to v3 yet, or that are planned to be removed in v3. Please feel free to share your thoughts about these decisions in [Discord](https://discord.gg/Ykhr738dUe) and we'll be happy to discuss them.
183
+
This section lists v2 features that haven't been migrated to v3 yet, or that are planned to be removed in v3. Please feel free to share your thoughts about these decisions in [Discord](https://discord.gg/Ykhr738dUe), and we'll be happy to discuss them.
184
184
185
185
### Automatic password hashing
186
186
187
187
The `@password` attribute is removed in v3. We believe most people will use a more sophisticated authentication system than a simple id/password mechanism.
188
188
189
189
### Field-level access control
190
190
191
-
Not supported yet but will be added soon with some design changes.
191
+
Not supported yet, but will be added soon with some design changes.
192
+
193
+
### Data encryption
194
+
195
+
Not supported yet, but will be added soon.
192
196
193
197
### Zod integration
194
198
195
-
Not supported yet but will be added soon with some design changes.
199
+
Not supported yet, but will be added soon with some design changes.
196
200
197
201
### Checking permissions without querying the database
198
202
199
203
The [check()](/docs/guides/check-permission) feature is removed due to low popularity.
200
204
201
205
### tRPC integration
202
206
203
-
[TRPC](https://trpc.io/) is TypeScriptinference heavy, and stacking it over ZenStack generates additional complexities and pressure to the compiler. We're evaluating the best way to integrate it in v3, and no concrete plan is in place yet. At least there's no plan to directly migrate the code-generationbased approach in v2.
207
+
[TRPC](https://trpc.io/) is TypeScript-inference heavy, and stacking it over ZenStack generates additional complexities and pressure on the compiler. We're evaluating the best way to integrate it in v3, and no concrete plan is in place yet. At least there's no plan to migrate the code-generation-based approach in v2 directly.
204
208
205
209
### OpenAPI spec generation
206
210
207
-
The [OpenAPI plugin](/docs/reference/plugins/openapi)is not migrated to v3 yet and will be added later with some redesign.
211
+
The [OpenAPI plugin](/docs/reference/plugins/openapi)has not migrated to v3 yet and will be added later with some redesign.
208
212
209
213
### SWR integration
210
214
@@ -214,4 +218,4 @@ The [SWR plugin](https://swr.vercel.app/) is removed due to low popularity.
214
218
215
219
### Is data migration needed?
216
220
217
-
No. From database schema point of view, v3 is fully backwardcompatible with v2.
221
+
No. From the database schema point of view, v3 is fully backward-compatible with v2.
0 commit comments