-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1334 from Giveth/3752_add_unique_index_for_sybil_…
…table Add unique index for sybil table
- Loading branch information
Showing
4 changed files
with
89 additions
and
7 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
migration/1708256080054-add_unique_index_for_sybil_table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddUniqueIndexForSybilTable1708256080054 | ||
implements MigrationInterface | ||
{ | ||
async up(queryRunner: QueryRunner): Promise<void> { | ||
// Step 1: Identify and Resolve Duplicates | ||
// Example strategy: Keep the first record and delete the rest | ||
await queryRunner.query(` | ||
DELETE FROM sybil | ||
WHERE id NOT IN ( | ||
SELECT MIN(id) | ||
FROM sybil | ||
GROUP BY "userId", "qfRoundId" | ||
); | ||
`); | ||
|
||
// Step 2: Create Unique Index | ||
await queryRunner.query(` | ||
CREATE UNIQUE INDEX "IDX_USERID_QFROUNDID" ON "sybil" ("userId", "qfRoundId"); | ||
`); | ||
} | ||
|
||
async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
DROP INDEX "IDX_USERID_QFROUNDID"; | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Field, ID, ObjectType } from 'type-graphql'; | ||
import { | ||
PrimaryGeneratedColumn, | ||
Column, | ||
Entity, | ||
ManyToOne, | ||
RelationId, | ||
BaseEntity, | ||
UpdateDateColumn, | ||
CreateDateColumn, | ||
} from 'typeorm'; | ||
import { User } from './user'; | ||
import { QfRound } from './qfRound'; | ||
|
||
@ObjectType() | ||
@Entity() | ||
export class UserPassportScore extends BaseEntity { | ||
@Field(type => ID) | ||
@PrimaryGeneratedColumn() | ||
readonly id: number; | ||
|
||
@Field({ nullable: false }) | ||
@Column('number') | ||
passportScore: number; | ||
|
||
@Field(type => User) | ||
@ManyToOne(type => User, { eager: true }) | ||
user: User; | ||
|
||
@RelationId((userPassportScore: UserPassportScore) => userPassportScore.user) | ||
@Column() | ||
userId: number; | ||
|
||
@Field(type => QfRound) | ||
@ManyToOne(type => QfRound, { eager: true }) | ||
qfRound: QfRound; | ||
|
||
@RelationId( | ||
(userPassportScore: UserPassportScore) => userPassportScore.qfRound, | ||
) | ||
@Column() | ||
qfRoundId: number; | ||
|
||
@UpdateDateColumn() | ||
updatedAt: Date; | ||
|
||
@CreateDateColumn() | ||
createdAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters