diff --git a/packages/twenty-server/src/database/typeorm/core/migrations/common/1734355945585-add-unique-index-on-subdomain.ts b/packages/twenty-server/src/database/typeorm/core/migrations/common/1734355945585-add-unique-index-on-subdomain.ts new file mode 100644 index 000000000000..c44b731fe1c0 --- /dev/null +++ b/packages/twenty-server/src/database/typeorm/core/migrations/common/1734355945585-add-unique-index-on-subdomain.ts @@ -0,0 +1,19 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddUniqueIndexOnSubdomain1734355945585 + implements MigrationInterface +{ + name = 'AddUniqueIndexOnSubdomain1734355945585'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "core"."workspace" ADD CONSTRAINT "UQ_cba6255a24deb1fff07dd7351b8" UNIQUE ("subdomain")`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "core"."workspace" DROP CONSTRAINT "UQ_cba6255a24deb1fff07dd7351b8"`, + ); + } +} diff --git a/packages/twenty-server/src/engine/core-modules/workspace/workspace.entity.ts b/packages/twenty-server/src/engine/core-modules/workspace/workspace.entity.ts index b80ecad5ecce..5f8e89af34c1 100644 --- a/packages/twenty-server/src/engine/core-modules/workspace/workspace.entity.ts +++ b/packages/twenty-server/src/engine/core-modules/workspace/workspace.entity.ts @@ -144,7 +144,7 @@ export class Workspace { databaseSchema: string; @Field() - @Column() + @Column({ unique: true }) subdomain: string; @Field()