From af5e22f562f1543776c80ad237b249e4dc506e3f Mon Sep 17 00:00:00 2001 From: = Date: Tue, 21 Oct 2025 00:36:33 +0530 Subject: [PATCH] feat: patched up migration to support pg14 --- backend/src/db/migrations/20251018061215_sub-org.ts | 6 +----- backend/src/services/org/org-service.ts | 6 ++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/src/db/migrations/20251018061215_sub-org.ts b/backend/src/db/migrations/20251018061215_sub-org.ts index bd577fe75..d048a23d3 100644 --- a/backend/src/db/migrations/20251018061215_sub-org.ts +++ b/backend/src/db/migrations/20251018061215_sub-org.ts @@ -14,14 +14,10 @@ export async function up(knex: Knex): Promise { t.foreign("rootOrgId").references("id").inTable(TableName.Organization).onDelete("CASCADE"); t.dropUnique(["slug"]); + t.unique(["rootOrgId", "parentOrgId", "slug"]); }); // had to switch to raw for null not distinct - await knex.raw(` -ALTER TABLE "organization" -ADD CONSTRAINT "organization_root_parent_slug_unique" -UNIQUE ("rootOrgId", "parentOrgId", "slug") NULLS NOT DISTINCT; -`); } const hasIdentityOrgCol = await knex.schema.hasColumn(TableName.Identity, "orgId"); diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts index 6334322eb..265612d55 100644 --- a/backend/src/services/org/org-service.ts +++ b/backend/src/services/org/org-service.ts @@ -516,6 +516,12 @@ export const orgServiceFactory = ({ } } + if (slug) { + const existingOrg = await orgDAL.findOne({ slug, rootOrgId: null }); + if (existingOrg && existingOrg?.id !== orgId) + throw new BadRequestError({ message: `Organization with slug ${slug} already exist` }); + } + if (googleSsoAuthEnforced) { if (googleSsoAuthEnforced && currentOrg.authEnforced) { throw new BadRequestError({