Skip to content

Commit

Permalink
feat(database): add unique constraint on workspace subdomain (#9084)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AMoreaux authored Dec 16, 2024
1 parent 33b0286 commit 4e329d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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"`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class Workspace {
databaseSchema: string;

@Field()
@Column()
@Column({ unique: true })
subdomain: string;

@Field()
Expand Down

0 comments on commit 4e329d0

Please sign in to comment.