diff --git a/migration/1707343258512-addsybilTableEntity.ts b/migration/1707343258512-addsybilTableEntity.ts new file mode 100644 index 000000000..304984530 --- /dev/null +++ b/migration/1707343258512-addsybilTableEntity.ts @@ -0,0 +1,80 @@ +import { + MigrationInterface, + QueryRunner, + Table, + TableForeignKey, +} from 'typeorm'; + +export class addsybilTableEntity1707343258512 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.createTable( + new Table({ + name: 'sybil', + columns: [ + { + name: 'id', + type: 'int', + isPrimary: true, + isGenerated: true, + generationStrategy: 'increment', + }, + { + name: 'confirmedSybil', + type: 'boolean', + isNullable: false, + default: false, + }, + { + name: 'userId', + type: 'int', + }, + { + name: 'qfRoundId', + type: 'int', + }, + ], + }), + true, + ); + + await queryRunner.createForeignKey( + 'sybil', + new TableForeignKey({ + columnNames: ['userId'], + referencedColumnNames: ['id'], + referencedTableName: 'user', + onDelete: 'CASCADE', + }), + ); + + await queryRunner.createForeignKey( + 'sybil', + new TableForeignKey({ + columnNames: ['qfRoundId'], + referencedColumnNames: ['id'], + referencedTableName: 'qfRound', + onDelete: 'CASCADE', + }), + ); + } + + public async down(queryRunner: QueryRunner): Promise { + const table = await queryRunner.getTable('sybil'); + const userForeignKey = table!.foreignKeys.find( + fk => fk.columnNames.indexOf('userId') !== -1, + ); + const qfRoundForeignKey = table!.foreignKeys.find( + fk => fk.columnNames.indexOf('qfRoundId') !== -1, + ); + + if (userForeignKey) { + await queryRunner.dropForeignKey('sybil', userForeignKey); + } + + if (qfRoundForeignKey) { + await queryRunner.dropForeignKey('sybil', qfRoundForeignKey); + } + + await queryRunner.dropTable('sybil'); + } +} diff --git a/src/entities/entities.ts b/src/entities/entities.ts index 594ea5c47..04d3d198e 100644 --- a/src/entities/entities.ts +++ b/src/entities/entities.ts @@ -44,6 +44,7 @@ import { QfRoundHistory } from './qfRoundHistory'; import { ProjectEstimatedMatchingView } from './ProjectEstimatedMatchingView'; import { AnchorContractAddress } from './anchorContractAddress'; import { RecurringDonation } from './recurringDonation'; +import { Sybil } from './sybil'; export const getEntities = (): DataSourceOptions['entities'] => { return [ @@ -101,6 +102,7 @@ export const getEntities = (): DataSourceOptions['entities'] => { QfRound, QfRoundHistory, + Sybil, AnchorContractAddress, RecurringDonation, diff --git a/src/entities/sybil.ts b/src/entities/sybil.ts new file mode 100644 index 000000000..18fbeee71 --- /dev/null +++ b/src/entities/sybil.ts @@ -0,0 +1,39 @@ +import { Field, ID, ObjectType } from 'type-graphql'; +import { + PrimaryGeneratedColumn, + Column, + Entity, + ManyToOne, + RelationId, + BaseEntity, +} from 'typeorm'; +import { User } from './user'; +import { QfRound } from './qfRound'; + +@ObjectType() +@Entity() +export class Sybil extends BaseEntity { + @Field(type => ID) + @PrimaryGeneratedColumn() + readonly id: number; + + @Field({ nullable: false }) + @Column('boolean', { nullable: false, default: false }) + confirmedSybil: boolean; + + @Field(type => User) + @ManyToOne(type => User, { eager: true }) + user: User; + + @RelationId((sybil: Sybil) => sybil.user) + @Column() + userId: number; + + @Field(type => QfRound) + @ManyToOne(type => QfRound, { eager: true }) + qfRound: QfRound; + + @RelationId((sybil: Sybil) => sybil.qfRound) + @Column() + qfRoundId: number; +}