Skip to content

Commit

Permalink
add sybil entity to the database
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed Feb 8, 2024
1 parent 2c4a95d commit ddee0e5
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
80 changes: 80 additions & 0 deletions migration/1707343258512-addsybilTableEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {
MigrationInterface,
QueryRunner,
Table,
TableForeignKey,
} from 'typeorm';

export class addsybilTableEntity1707343258512 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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');
}
}
2 changes: 2 additions & 0 deletions src/entities/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -101,6 +102,7 @@ export const getEntities = (): DataSourceOptions['entities'] => {

QfRound,
QfRoundHistory,
Sybil,

AnchorContractAddress,
RecurringDonation,
Expand Down
39 changes: 39 additions & 0 deletions src/entities/sybil.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit ddee0e5

Please sign in to comment.