feat(database): add unique constraint on workspace subdomain (#9084)

Added a unique constraint to the "subdomain" column in the workspace
entity to ensure no duplicate subdomains exist in the database. Included
a TypeORM migration script to enforce this change at the database level.
This commit is contained in:
Antoine Moreaux
2024-12-16 19:41:18 +01:00
committed by GitHub
parent 33b028658e
commit 4e329d08b0
2 changed files with 20 additions and 1 deletions

View File

@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddUniqueIndexOnSubdomain1734355945585
implements MigrationInterface
{
name = 'AddUniqueIndexOnSubdomain1734355945585';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."workspace" ADD CONSTRAINT "UQ_cba6255a24deb1fff07dd7351b8" UNIQUE ("subdomain")`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."workspace" DROP CONSTRAINT "UQ_cba6255a24deb1fff07dd7351b8"`,
);
}
}

View File

@ -144,7 +144,7 @@ export class Workspace {
databaseSchema: string;
@Field()
@Column()
@Column({ unique: true })
subdomain: string;
@Field()