Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

add zod validation to the migration

Roman Pominovf2907eb73cb2
diff --git a/packages/prisma-client/package.json b/packages/prisma-client/package.json
index 07fb8ebedd..3d0c374771 100644
--- a/packages/prisma-client/package.json
+++ b/packages/prisma-client/package.json
@@ -29,6 +29,7 @@
"minimist": "^1.2.6",
"tsx": "^3.9.0",
"umzug": "^3.2.1",
- "uuid": "^9.0.0"
+ "uuid": "^9.0.0",
+ "zod": "^3.19.0"
}
}
diff --git a/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/migration.ts b/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/migration.ts
index f11c0b3318..d6138f1a2d 100644
--- a/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/migration.ts
+++ b/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/migration.ts
@@ -1,5 +1,22 @@
import { PrismaClient, Prisma } from "./client";
import { v4 as uuid } from "uuid";
+import { z } from "zod";
+
+const TreeHistorySchema = z.array(z.string());
+
+const PageSchema = z.object({
+ id: z.string(),
+ name: z.string(),
+ path: z.string(),
+ title: z.string(),
+ meta: z.record(z.string(), z.string()),
+ treeId: z.string(),
+});
+
+const PagesSchema = z.object({
+ homePage: PageSchema,
+ pages: z.array(PageSchema),
+});
export default () => {
const client = new PrismaClient();
@@ -14,25 +31,27 @@ export default () => {
(project) =>
project.devTreeId === tree.id ||
project.prodTreeId === tree.id ||
- JSON.parse(project.prodTreeIdHistory).includes(tree.id)
+ TreeHistorySchema.parse(project.prodTreeIdHistory).includes(tree.id)
);
if (project === undefined) {
continue;
}
+ const pages = PagesSchema.parse({
+ homePage: {
+ id: uuid(),
+ name: "Home",
+ path: "",
+ title: "Home",
+ meta: {},
+ treeId: tree.id,
+ },
+ pages: [],
+ });
+
builds.push({
- pages: JSON.stringify({
- homePage: {
- id: uuid(),
- name: "Home",
- path: "",
- title: "Home",
- meta: {},
- treeId: tree.id,
- },
- pages: [],
- }),
+ pages: JSON.stringify(pages),
isDev: project.devTreeId === tree.id,
isProd: project.prodTreeId === tree.id,
projectId: project.id,
diff --git a/yarn.lock b/yarn.lock
index b58658df2c..0bd55a29eb 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -17951,6 +17951,11 @@ zod@^3.17.3:
resolved "https://registry.yarnpkg.com/zod/-/zod-3.17.3.tgz#86abbc670ff0063a4588d85a4dcc917d6e4af2ba"
integrity sha512-4oKP5zvG6GGbMlqBkI5FESOAweldEhSOZ6LI6cG+JzUT7ofj1ZOC0PJudpQOpT1iqOFpYYtX5Pw0+o403y4bcg==
+zod@^3.19.0:
+ version "3.19.0"
+ resolved "https://registry.yarnpkg.com/zod/-/zod-3.19.0.tgz#a9303fcaed0950a3dc57bf35cc11f6282d4f52f2"
+ integrity sha512-Yw0qvUsCNGBe5YacikdMt5gVYeUuaEFVDIHKMfElrGSaBhwR3CQK6vOzgfAJOjTdGIhEeoaj8GtT+NDZrepZbw==
+
zwitch@^1.0.0:
version "1.0.5"
resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-1.0.5.tgz#d11d7381ffed16b742f6af7b3f223d5cd9fe9920"