79351452

Date: 2025-01-13 07:45:27
Score: 0.5
Natty:
Report link

To create separate unique constraints on both userguid and username columns in TypeORM, you don't need to use the @Unique decorator at the class level. Instead, you can apply the @Unique decorator at the property level for each column.

So you can change from this:

@Entity({ name: "USERS" })
@Unique("USERS_UQ", ["userName"])
export class UserORM {...}

To:

@Entity({ name: "USERS" })
export class UserORM {
...
   @Column({
       name: "USERGUID",
       type: "varchar2",
       length: 256,
       nullable: false,
    })
  @Unique("USERS_UQ_USERGUID", ["userGUID"])
  userGUID!: string;

  @Column({
    name: "USERNAME",
    type: "varchar2",
    length: 256,
    nullable: false,
 })
 @Unique("USERS_UQ_USERNAME", ["userName"])
 userName!: string;
...
}

This approach generates two distinct UNIQUE constraints for the userguid and username columns when you synchronize your database schema.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Unique
  • User mentioned (0): @Unique
  • Low reputation (0.5):
Posted by: Daniel Bueno