-
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.
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
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,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'); | ||
} | ||
} |
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,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; | ||
} |