From 4757fd019c3958eab173697c5f09d5269d2788fa Mon Sep 17 00:00:00 2001 From: Amin Latifi Date: Fri, 1 Nov 2024 19:26:01 +0330 Subject: [PATCH] Added unique index on donation transaction id --- ...30476526611-addDonationTransactionUniqIdx.ts | 17 +++++++++++++++++ src/entities/donation.ts | 1 + 2 files changed, 18 insertions(+) create mode 100644 migration/1730476526611-addDonationTransactionUniqIdx.ts diff --git a/migration/1730476526611-addDonationTransactionUniqIdx.ts b/migration/1730476526611-addDonationTransactionUniqIdx.ts new file mode 100644 index 000000000..3d7110a44 --- /dev/null +++ b/migration/1730476526611-addDonationTransactionUniqIdx.ts @@ -0,0 +1,17 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddDonationTransactionUniqIdx1730476526611 + implements MigrationInterface +{ + name = 'AddDonationTransactionUniqIdx1730476526611'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE UNIQUE INDEX "unique_transaction_id" ON "donation" ("transactionId") `, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX "public"."unique_transaction_id"`); + } +} diff --git a/src/entities/donation.ts b/src/entities/donation.ts index 81e883b95..0462a0262 100644 --- a/src/entities/donation.ts +++ b/src/entities/donation.ts @@ -54,6 +54,7 @@ export class Donation extends BaseEntity { @Field({ nullable: true }) @Column({ nullable: true }) // It's transactionHash for crypto donation, and trackingCode for fiat donation + @Index('unique_transaction_id', { unique: true }) transactionId: string; @Field({ nullable: true })