feat(SPG-773): set item name to unique
parent
ffcbf65d9d
commit
aaee458df6
|
@ -0,0 +1,29 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class UniqueNameItem1722922766205 implements MigrationInterface {
|
||||
name = 'UniqueNameItem1722922766205';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item_bundlings" DROP CONSTRAINT "FK_a50e7abf2caba4d0394f3726b86"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "items" ADD CONSTRAINT "UQ_213736582899b3599acaade2cd1" UNIQUE ("name")`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item_bundlings" ADD CONSTRAINT "FK_a50e7abf2caba4d0394f3726b86" FOREIGN KEY ("item_bundling_id") REFERENCES "items"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item_bundlings" DROP CONSTRAINT "FK_a50e7abf2caba4d0394f3726b86"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "items" DROP CONSTRAINT "UQ_213736582899b3599acaade2cd1"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item_bundlings" ADD CONSTRAINT "FK_a50e7abf2caba4d0394f3726b86" FOREIGN KEY ("item_bundling_id") REFERENCES "items"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ export class ItemModel
|
|||
extends BaseStatusModel<ItemEntity>
|
||||
implements ItemEntity
|
||||
{
|
||||
@Column('varchar', { name: 'name' })
|
||||
@Column('varchar', { name: 'name', unique: true })
|
||||
name: string;
|
||||
|
||||
@Column('varchar', { name: 'image_url', nullable: true })
|
||||
|
|
|
@ -33,7 +33,7 @@ export class CreateItemManager extends BaseCreateManager<ItemEntity> {
|
|||
}
|
||||
|
||||
get uniqueColumns(): columnUniques[] {
|
||||
return [];
|
||||
return [{ column: 'name' }];
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
|
|
Loading…
Reference in New Issue