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.

fix: free up the wstd subdomain after project was deleted (#3869)

Oleg Isonenee7987e1345e
diff --git a/packages/prisma-client/prisma/migrations/20240807000548_deleted-project-free-domain/migration.sql b/packages/prisma-client/prisma/migrations/20240807000548_deleted-project-free-domain/migration.sql
new file mode 100644
index 0000000000..62e1c10846
--- /dev/null
+++ b/packages/prisma-client/prisma/migrations/20240807000548_deleted-project-free-domain/migration.sql
@@ -0,0 +1,3 @@
+-- to avoid some issues with backups we are using explicit schemas for "extensions" functions
+
+UPDATE "Project" SET "domain"=extensions.uuid_generate_v4() WHERE "isDeleted" = true;
\ No newline at end of file
diff --git a/packages/project/src/db/project.ts b/packages/project/src/db/project.ts
index 049a18f13c..25672e51b0 100644
--- a/packages/project/src/db/project.ts
+++ b/packages/project/src/db/project.ts
@@ -7,6 +7,7 @@ import {
import { createBuild } from "@webstudio-is/project-build/index.server";
import { MarketplaceApprovalStatus, Project, Title } from "../shared/schema";
import { generateDomain, validateProjectDomain } from "./project-domain";
+import { nanoid } from "nanoid";
export const loadById = async (
projectId: Project["id"],
@@ -91,10 +92,14 @@ export const markAsDeleted = async (
return { errors: "Only the owner can delete the project" };
}
- return await prisma.project.update({
- where: { id: projectId },
- data: { isDeleted: true },
- });
+ return await context.postgrest.client
+ .from("Project")
+ .update({
+ isDeleted: true,
+ // Free up the subdomain
+ domain: nanoid(),
+ })
+ .eq("id", projectId);
};
const assertEditPermission = async (projectId: string, context: AppContext) => {