-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(database): add unique constraint on workspace subdomain #9084
Conversation
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Added a unique constraint to the workspace subdomain field to prevent duplicate subdomains across workspaces, with database-level enforcement through TypeORM.
- Added
{ unique: true }
tosubdomain
column in/packages/twenty-server/src/engine/core-modules/workspace/workspace.entity.ts
- Created migration
/packages/twenty-server/src/database/typeorm/core/migrations/common/1734355945585-add-unique-index-on-subdomain.ts
to enforce uniqueness at database level - Potential risk: Migration could fail if duplicate subdomains exist in production database
2 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile
@Column({ unique: true }) | ||
subdomain: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: No default value provided for required unique field. Could cause issues during workspace creation if subdomain is not explicitly set.
@Column({ unique: true }) | ||
subdomain: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider adding a validation decorator to enforce subdomain format (e.g., alphanumeric, no spaces).
name = 'AddUniqueIndexOnSubdomain1734355945585' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "core"."workspace" ADD CONSTRAINT "UQ_cba6255a24deb1fff07dd7351b8" UNIQUE ("subdomain")`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider adding a NOT NULL constraint if subdomain is required, since NULL values are allowed with UNIQUE constraints
I'm afraid this is too late and we have to create an upgrade command to cleanup? Or are we sure the database is clean already? |
I can't check in the prod database. There are probably no duplicate subdomains. But I can add a command to be sure. |
Yes if you don't mind adding a command (it will be version 0.40) that's the process we usually adopt, to be safe. See upgrade-version folder. Thanks! |
Log
|
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.