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 })