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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
new migration
Roman Pominov4bcf34ef8769
diff --git a/packages/prisma-client/prisma/migrations/20220909124449_add_builds/migration.sql b/packages/prisma-client/prisma/migrations/20220909124449_add_builds/migration.sqldeleted file mode 100644index 400ff3a365..0000000000--- a/packages/prisma-client/prisma/migrations/20220909124449_add_builds/migration.sql+++ /dev/null@@ -1,14 +0,0 @@--- CreateTable-CREATE TABLE "Build" (- "id" TEXT NOT NULL,- "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,- "pages" TEXT NOT NULL,- "isDev" BOOLEAN NOT NULL,- "isProd" BOOLEAN NOT NULL,- "projectId" TEXT NOT NULL,-- CONSTRAINT "Build_pkey" PRIMARY KEY ("id")-);---- AddForeignKey-ALTER TABLE "Build" ADD CONSTRAINT "Build_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;diff --git a/packages/prisma-client/prisma/migrations/20220909131750_remove_legacy_project_fields/migration.sql b/packages/prisma-client/prisma/migrations/20220909131750_remove_legacy_project_fields/migration.sqldeleted file mode 100644index 24114df501..0000000000--- a/packages/prisma-client/prisma/migrations/20220909131750_remove_legacy_project_fields/migration.sql+++ /dev/null@@ -1,4 +0,0 @@--- AlterTable-ALTER TABLE "Project" DROP COLUMN "devTreeId",-DROP COLUMN "prodTreeId",-DROP COLUMN "prodTreeIdHistory";diff --git a/packages/prisma-client/prisma/migrations/20220913130338_add_builds/migration.sql b/packages/prisma-client/prisma/migrations/20220913130338_add_builds/migration.sqlnew file mode 100644index 0000000000..89ef499d60--- /dev/null+++ b/packages/prisma-client/prisma/migrations/20220913130338_add_builds/migration.sql@@ -0,0 +1,19 @@+-- AlterTable+ALTER TABLE "Project" ADD COLUMN "devBuildId" TEXT;++-- CreateTable+CREATE TABLE "Build" (+ "id" TEXT NOT NULL,+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,+ "pages" TEXT NOT NULL,+ "projectId" TEXT,+ "isCurrentProd" BOOLEAN NOT NULL,++ CONSTRAINT "Build_pkey" PRIMARY KEY ("id")+);++-- AddForeignKey+ALTER TABLE "Project" ADD CONSTRAINT "Project_devBuildId_fkey" FOREIGN KEY ("devBuildId") REFERENCES "Build"("id") ON DELETE SET NULL ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "Build" ADD CONSTRAINT "Build_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE SET NULL ON UPDATE CASCADE;diff --git a/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/migration.ts b/packages/prisma-client/prisma/migrations/20220913130446_initialize_builds/migration.tssimilarity index 64%rename from packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/migration.tsrename to packages/prisma-client/prisma/migrations/20220913130446_initialize_builds/migration.tsindex 2df896a683..cd702a4423 100644--- a/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/migration.ts+++ b/packages/prisma-client/prisma/migrations/20220913130446_initialize_builds/migration.ts@@ -1,4 +1,4 @@-import { PrismaClient, Prisma } from "./client";+import { PrismaClient, type Project, type Tree } from "./client";import { v4 as uuid } from "uuid";import { z } from "zod";@@ -18,6 +18,11 @@ const PagesSchema = z.object({pages: z.array(PageSchema),});+const isInHistory = (project: Project, tree: Tree) =>+ TreeHistorySchema.parse(JSON.parse(project.prodTreeIdHistory)).includes(+ tree.id+ );+export default () => {const client = new PrismaClient({// Uncomment to see the queries in console as the migration runs@@ -27,16 +32,12 @@ export default () => {const trees = await prisma.tree.findMany();const projects = await prisma.project.findMany();- const builds: Prisma.BuildCreateManyInput[] = [];-for (const tree of trees) {const project = projects.find((project) =>project.devTreeId === tree.id ||project.prodTreeId === tree.id ||- TreeHistorySchema.parse(- JSON.parse(project.prodTreeIdHistory)- ).includes(tree.id)+ isInHistory(project, tree));if (project === undefined) {@@ -55,14 +56,20 @@ export default () => {pages: [],});- builds.push({- pages: JSON.stringify(pages),- isDev: project.devTreeId === tree.id,- isProd: project.prodTreeId === tree.id,- projectId: project.id,+ const build = await prisma.build.create({+ data: {+ pages: JSON.stringify(pages),+ isCurrentProd: project.prodTreeId === tree.id,+ projectId: isInHistory(project, tree) ? project.id : undefined,+ },});- }- await prisma.build.createMany({ data: builds });+ if (project.devTreeId === tree.id) {+ await prisma.project.update({+ where: { id: project.id },+ data: { devBuildId: build.id },+ });+ }+ }});};diff --git a/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/schema.prisma b/packages/prisma-client/prisma/migrations/20220913130446_initialize_builds/schema.prismasimilarity index 60%rename from packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/schema.prismarename to packages/prisma-client/prisma/migrations/20220913130446_initialize_builds/schema.prismaindex a9532b86b0..d822e82ee8 100644--- a/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/schema.prisma+++ b/packages/prisma-client/prisma/migrations/20220913130446_initialize_builds/schema.prisma@@ -1,5 +1,5 @@// DO NOT EDIT THIS FILE!-// This a copy of your schema.prisma that corresponds to the state of the database+// This is a copy of your schema.prisma that corresponds to the state of the database// when all migrations up until this one are applied.// It's used to generate a Prisma Client for the migration.@@ -28,17 +28,16 @@ enum Location {}model Asset {- id String @id @default(uuid())- project Project @relation(fields: [projectId], references: [id])- projectId String- format String?- size Int- width Decimal?- height Decimal?- name String- alt String?- location Location- createdAt DateTime @default(now())+ id String @id @default(uuid())+ project Project @relation(fields: [projectId], references: [id])+ projectId String+ format String?+ size Int+ name String+ description String?+ location Location+ createdAt DateTime @default(now())+ meta String @default("{}")}model User {@@ -60,9 +59,17 @@ model Project {user User? @relation(fields: [userId], references: [id])userId String?assets Asset[]- build Build[]- // tmp+ // Mutable dev build+ // (Nullable temporarily)+ devBuild Build? @relation(name: "devBuild", fields: [devBuildId], references: [id])+ devBuildId String?++ // History of immutable published builds+ // one of which has isCurrentProd=true+ buildsHistory Build[] @relation(name: "buildsHistory")++ // To be deletedprodTreeId String? // exists when publisheddevTreeId StringprodTreeIdHistory String @default("[]")@@ -72,10 +79,14 @@ model Build {id String @id @default(uuid())createdAt DateTime @default(now())pages String- isDev Boolean // exctly one is true per project- isProd Boolean // at most one is true per project (none if not published)- project Project @relation(fields: [projectId], references: [id])- projectId String++ // Used only for immutable published builds+ project Project? @relation(name: "buildsHistory", fields: [projectId], references: [id])+ projectId String?+ isCurrentProd Boolean++ // This is not used. Prisma requires all relations to be defined on both sides.+ devProject__ Project[] @relation(name: "devBuild")}model Tree {diff --git a/packages/prisma-client/prisma/migrations/20220913132316_cleanup_builds/migration.sql b/packages/prisma-client/prisma/migrations/20220913132316_cleanup_builds/migration.sqlnew file mode 100644index 0000000000..e71f3a5014--- /dev/null+++ b/packages/prisma-client/prisma/migrations/20220913132316_cleanup_builds/migration.sql@@ -0,0 +1,11 @@+-- DropForeignKey+ALTER TABLE "Project" DROP CONSTRAINT "Project_devBuildId_fkey";++-- AlterTable+ALTER TABLE "Project" DROP COLUMN "devTreeId",+DROP COLUMN "prodTreeId",+DROP COLUMN "prodTreeIdHistory",+ALTER COLUMN "devBuildId" SET NOT NULL;++-- AddForeignKey+ALTER TABLE "Project" ADD CONSTRAINT "Project_devBuildId_fkey" FOREIGN KEY ("devBuildId") REFERENCES "Build"("id") ON DELETE RESTRICT ON UPDATE CASCADE;diff --git a/packages/prisma-client/prisma/schema.prisma b/packages/prisma-client/prisma/schema.prismaindex 3933ee3032..959d4eb53e 100644--- a/packages/prisma-client/prisma/schema.prisma+++ b/packages/prisma-client/prisma/schema.prisma@@ -54,17 +54,28 @@ model Project {user User? @relation(fields: [userId], references: [id])userId String?assets Asset[]- build Build[]++ // Mutable dev build+ devBuild Build @relation(name: "devBuild", fields: [devBuildId], references: [id])+ devBuildId String++ // History of immutable published builds+ // one of which has isCurrentProd=true+ buildsHistory Build[] @relation(name: "buildsHistory")}model Build {id String @id @default(uuid())createdAt DateTime @default(now())pages String- isDev Boolean // exctly one is true per project- isProd Boolean // at most one is true per project (none if not published)- project Project @relation(fields: [projectId], references: [id])- projectId String++ // Used only for immutable published builds+ project Project? @relation(name: "buildsHistory", fields: [projectId], references: [id])+ projectId String?+ isCurrentProd Boolean++ // This is not used. Prisma requires all relations to be defined on both sides.+ devProject__ Project[] @relation(name: "devBuild")}model Tree {