Fix soft delete unique constraints to allow reusing unique values after deletion (#13615)

Closes [#1297](https://github.com/twentyhq/core-team-issues/issues/1297)
This commit is contained in:
Abdul Rahman
2025-08-05 11:27:02 +05:30
committed by GitHub
parent ade7f8b6ae
commit b2452e83ad
5 changed files with 89 additions and 17 deletions
@@ -14,7 +14,6 @@ import {
OneToMany,
PrimaryGeneratedColumn,
Relation,
Unique,
UpdateDateColumn,
} from 'typeorm';
@@ -36,10 +35,14 @@ registerEnumType(PermissionsOnAllObjectRecords, {
@Entity({ name: 'userWorkspace', schema: 'core' })
@ObjectType()
@Unique('IDX_USER_WORKSPACE_USER_ID_WORKSPACE_ID_UNIQUE', [
'userId',
'workspaceId',
])
@Index(
'IDX_USER_WORKSPACE_USER_ID_WORKSPACE_ID_UNIQUE',
['userId', 'workspaceId'],
{
unique: true,
where: '"deletedAt" IS NULL',
},
)
@Index('IDX_USER_WORKSPACE_USER_ID', ['userId'])
@Index('IDX_USER_WORKSPACE_WORKSPACE_ID', ['workspaceId'])
export class UserWorkspace {