Skip to content

Commit

Permalink
add fix unique index on donation entity
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed Dec 7, 2023
1 parent a5ff127 commit 3438da5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
27 changes: 27 additions & 0 deletions migration/1701916750562-modifyDonationUniquenessIndex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { logger } from '../src/utils/logger';

export class modifyDonationUniquenessIndex1701916750562
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX IF EXISTS "UQ_c9db9fd133378af80c3521bb146";`,
);
await queryRunner.query(`
CREATE UNIQUE INDEX IF NOT EXISTS "UQ_c9db9fd133378af80c3521bb146"
ON public.donation (transactionId, toWalletAddress, currency)
WHERE transactionId IS NOT NULL;
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX IF EXISTS "UQ_c9db9fd133378af80c3521bb146";`,
);
await queryRunner.query(`
CREATE UNIQUE INDEX IF NOT EXISTS "UQ_c9db9fd133378af80c3521bb146"
ON public.donation (transactionId, toWalletAddress, currency)
`);
}
}
3 changes: 1 addition & 2 deletions src/entities/donation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ export enum SortField {
@Entity()
@ObjectType()
// https://typeorm.io/#/decorator-reference/unique
@Unique(['transactionId', 'toWalletAddress', 'currency'])
export class Donation extends BaseEntity {
@Field(type => ID)
@PrimaryGeneratedColumn()
id: number;

@Field({ nullable: true })
@Field()
@Column({ nullable: true })
// It's transactionHash for crypto donation, and trackingCode for fiat donation
transactionId: string;
Expand Down

0 comments on commit 3438da5

Please sign in to comment.