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 Pominov254181eb9c65
diff --git a/packages/prisma-client/package.json b/packages/prisma-client/package.jsonindex 15f06d08d1..07fb8ebedd 100644--- a/packages/prisma-client/package.json+++ b/packages/prisma-client/package.json@@ -14,6 +14,7 @@"migrations": "./migrations-cli/cli.ts"},"devDependencies": {+ "@types/uuid": "^8.3.4","prisma": "^4.1.0"},"main": "src/index.ts",@@ -27,6 +28,7 @@"execa": "^6.1.0","minimist": "^1.2.6","tsx": "^3.9.0",- "umzug": "^3.2.1"+ "umzug": "^3.2.1",+ "uuid": "^9.0.0"}}diff --git a/packages/prisma-client/prisma/migrations/20220826083248_add_builds/migration.sql b/packages/prisma-client/prisma/migrations/20220826083248_add_builds/migration.sqldeleted file mode 100644index 6c3b5f2e7d..0000000000--- a/packages/prisma-client/prisma/migrations/20220826083248_add_builds/migration.sql+++ /dev/null@@ -1,119 +0,0 @@-/*- The MIT License (MIT)- Copyright (c) 2013 Jamar Parris-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.-- https://gist.github.com/jamarparris/6100413- */-CREATE OR REPLACE FUNCTION temporary_fn_generate_object_id() RETURNS varchar AS $$-DECLARE time_component bigint;-machine_id bigint := FLOOR(random() * 16777215);-process_id bigint;-seq_id bigint := FLOOR(random() * 16777215);-result varchar := '';-BEGIN-SELECT FLOOR(- EXTRACT(- EPOCH- FROM clock_timestamp()- )- ) INTO time_component;-SELECT pg_backend_pid() INTO process_id;-result := result || lpad(to_hex(time_component), 8, '0');-result := result || lpad(to_hex(machine_id), 6, '0');-result := result || lpad(to_hex(process_id), 4, '0');-result := result || lpad(to_hex(seq_id), 6, '0');-RETURN result;-END;-$$ LANGUAGE PLPGSQL;---CREATE TABLE "Build" (- "id" TEXT NOT NULL,- "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,- "pages" TEXT NOT NULL,- "projectProdId" TEXT,-- -- for data migration- "tmpTreeId" TEXT NOT NULL,-- CONSTRAINT "Build_pkey" PRIMARY KEY ("id")-);----- Create a Build for every Tree-INSERT INTO "Build" ("id", "pages", "tmpTreeId")-select gen_random_uuid()::text as id,- '{"homePage":{"id":"' || temporary_fn_generate_object_id() || '","name":"Home","path":"","title":"Home","meta":{},"treeId":"' || id || '"},"pages":[]}' as pages,- id as tmpTreeId-from "Tree";--DROP FUNCTION temporary_fn_generate_object_id;----- Add and set Project.devBuildId-ALTER TABLE "Project"-ADD COLUMN "devBuildId" TEXT;-UPDATE "Project"-SET "devBuildId" = (- SELECT "id"- FROM "Build"- WHERE "Build"."tmpTreeId" = "Project"."devTreeId"- );----- Make sure all Builds corresponding to a prodTreeId have createdAt more recent than other Builds-UPDATE "Build"-SET "createdAt" = clock_timestamp()-WHERE "Build"."tmpTreeId" IN (- SELECT "prodTreeId"- FROM "Project"- );----- Set Build.projectProdId-WITH prod_trees AS (- select id as project_id,- json_array_elements_text("prodTreeIdHistory"::json) as tree_id- from "Project"- union- select id as project_id,- "prodTreeId" as tree_id- from "Project"- where "prodTreeId" IS NOT NULL-)-UPDATE "Build"-SET "projectProdId" = project_id-FROM prod_trees-WHERE "Build"."tmpTreeId" = tree_id;---ALTER TABLE "Build" DROP COLUMN "tmpTreeId";----- AlterTable-ALTER TABLE "Project" DROP COLUMN "devTreeId",- DROP COLUMN "prodTreeId",- DROP COLUMN "prodTreeIdHistory",- ALTER COLUMN "devBuildId"-SET NOT NULL;----- CreateIndex-CREATE UNIQUE INDEX "Project_devBuildId_key" ON "Project"("devBuildId");----- AddForeignKey-ALTER TABLE "Project"-ADD CONSTRAINT "Project_devBuildId_fkey" FOREIGN KEY ("devBuildId") REFERENCES "Build"("id") ON DELETE RESTRICT ON UPDATE CASCADE;----- AddForeignKey-ALTER TABLE "Build"-ADD CONSTRAINT "Build_projectProdId_fkey" FOREIGN KEY ("projectProdId") REFERENCES "Project"("id") ON DELETE-SET NULL ON UPDATE CASCADE;\ No newline at end of filediff --git a/packages/prisma-client/prisma/migrations/20220909124449_add_builds/migration.sql b/packages/prisma-client/prisma/migrations/20220909124449_add_builds/migration.sqlnew file mode 100644index 0000000000..400ff3a365--- /dev/null+++ b/packages/prisma-client/prisma/migrations/20220909124449_add_builds/migration.sql@@ -0,0 +1,14 @@+-- 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/20220909124542_move_to_builds/migration.ts b/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/migration.tsnew file mode 100644index 0000000000..b0f4790365--- /dev/null+++ b/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/migration.ts@@ -0,0 +1,44 @@+import { PrismaClient, Prisma } from "./client";+import { v4 as uuidv4 } from "uuid";++export default () => {+ const client = new PrismaClient();+ return client.$transaction(async (prisma) => {+ 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 ||+ JSON.parse(project.prodTreeIdHistory).includes(tree.id)+ );++ if (project === undefined) {+ continue;+ }++ builds.push({+ pages: JSON.stringify({+ homePage: {+ id: uuidv4(),+ name: "Home",+ path: "",+ title: "Home",+ meta: {},+ treeId: tree.id,+ },+ pages: [],+ }),+ isDev: project.devTreeId === tree.id,+ isProd: project.prodTreeId === tree.id,+ projectId: project.id,+ });+ }++ await prisma.build.createMany({ data: builds });+ });+};diff --git a/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/schema.prisma b/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/schema.prismanew file mode 100644index 0000000000..a9532b86b0--- /dev/null+++ b/packages/prisma-client/prisma/migrations/20220909124542_move_to_builds/schema.prisma@@ -0,0 +1,96 @@+// DO NOT EDIT THIS FILE!+// This 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.++// This is your Prisma schema file,+// learn more about it in the docs: https://pris.ly/d/prisma-schema++generator client {+ provider = "prisma-client-js"+ previewFeatures = ["interactiveTransactions"]+ output = "client"+}++datasource db {+ provider = "postgres"+ url = env("DATABASE_URL")+}++model Team {+ id String @id @default(uuid())+ users User[]+}++enum Location {+ FS+ REMOTE+}++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())+}++model User {+ id String @id @default(uuid())+ email String? @unique+ provider String?+ image String?+ username String?+ createdAt DateTime @default(now())+ team Team? @relation(fields: [teamId], references: [id])+ teamId String?+ projects Project[]+}++model Project {+ id String @id @default(uuid())+ title String+ domain String @unique+ user User? @relation(fields: [userId], references: [id])+ userId String?+ assets Asset[]+ build Build[]++ // tmp+ prodTreeId String? // exists when published+ devTreeId String+ prodTreeIdHistory String @default("[]")+}++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+}++model Tree {+ id String @id @default(uuid())+ root String+}++model InstanceProps {+ id String @id @default(uuid())+ instanceId String+ treeId String+ props String @default("[]")+}++model Breakpoints {+ treeId String @id @default(uuid())+ values String @default("[]")+}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.sqlnew file mode 100644index 0000000000..24114df501--- /dev/null+++ b/packages/prisma-client/prisma/migrations/20220909131750_remove_legacy_project_fields/migration.sql@@ -0,0 +1,4 @@+-- AlterTable+ALTER TABLE "Project" DROP COLUMN "devTreeId",+DROP COLUMN "prodTreeId",+DROP COLUMN "prodTreeIdHistory";diff --git a/packages/prisma-client/prisma/schema.prisma b/packages/prisma-client/prisma/schema.prismaindex 6b16fba757..7f0b7c0c91 100644--- a/packages/prisma-client/prisma/schema.prisma+++ b/packages/prisma-client/prisma/schema.prisma@@ -49,24 +49,23 @@ model User {}model Project {- id String @id @default(uuid())- title String- domain String @unique- user User? @relation(fields: [userId], references: [id])- userId String?- assets Asset[]- devBuild Build @relation(name: "devBuild", fields: [devBuildId], references: [id])- devBuildId String @unique- prodBuilds Build[] @relation(name: "prodBuilds")+ id String @id @default(uuid())+ title String+ domain String @unique+ user User? @relation(fields: [userId], references: [id])+ userId String?+ assets Asset[]+ build Build[]}model Build {- id String @id @default(uuid())- createdAt DateTime @default(now())- pages String- projectDev Project? @relation(name: "devBuild")- projectProd Project? @relation(name: "prodBuilds", fields: [projectProdId], references: [id])- projectProdId String?+ 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}model Tree {diff --git a/yarn.lock b/yarn.lockindex aca7adcc70..b58658df2c 100644--- a/yarn.lock+++ b/yarn.lock@@ -5148,6 +5148,11 @@resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.6.tgz#250a7b16c3b91f672a24552ec64678eeb1d3a08d"integrity sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==+"@types/uuid@^8.3.4":+ version "8.3.4"+ resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"+ integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==+"@types/w3c-css-typed-object-model-level-1@^20180410.0.4":version "20180410.0.4"resolved "https://registry.yarnpkg.com/@types/w3c-css-typed-object-model-level-1/-/w3c-css-typed-object-model-level-1-20180410.0.4.tgz#76317f9c52140d731636d909830535b6484a3396"@@ -17291,6 +17296,11 @@ uuid@^8.3.2:resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==+uuid@^9.0.0:+ version "9.0.0"+ resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"+ integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==+uvu@^0.5.0:version "0.5.6"resolved "https://registry.yarnpkg.com/uvu/-/uvu-0.5.6.tgz#2754ca20bcb0bb59b64e9985e84d2e81058502df"