Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions migration/1779182511002-FixProjectQfRoundsPrimaryKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export class FixProjectQfRoundsPrimaryKey1779182511002
name = 'FixProjectQfRoundsPrimaryKey1779182511002';

public async up(queryRunner: QueryRunner): Promise<void> {
// Skip this migration in test environment
if (process.env.NODE_ENV === 'test' || process.env.ENVIRONMENT === 'test') {
return;
}
// Drop the materialized view that depends on the table
await queryRunner.query(`
DROP MATERIALIZED VIEW IF EXISTS project_actual_matching_view
Expand Down Expand Up @@ -267,6 +271,10 @@ export class FixProjectQfRoundsPrimaryKey1779182511002
}

public async down(queryRunner: QueryRunner): Promise<void> {
// Skip rollback in test environment
if (process.env.NODE_ENV === 'test' || process.env.ENVIRONMENT === 'test') {
return;
}
// Drop all indexes first
await queryRunner.query(`
DROP INDEX IF EXISTS "idx_project_qf_rounds_qf_round_sum_donation"
Expand Down
2 changes: 1 addition & 1 deletion src/entities/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export class Project extends BaseEntity {
@ManyToMany(_type => QfRound, qfRound => qfRound.projects, {
nullable: true,
})
@JoinTable()
@JoinTable({ name: 'project_qf_rounds_qf_round' })
qfRounds: QfRound[];

@Field(_type => [ProjectQfRound], { nullable: true })
Expand Down
15 changes: 9 additions & 6 deletions src/entities/projectQfRound.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
import { Field, ID, ObjectType, Float, Int } from 'type-graphql';
import {
PrimaryColumn,
PrimaryGeneratedColumn,
Column,
Entity,
ManyToOne,
BaseEntity,
CreateDateColumn,
UpdateDateColumn,
Index,
Unique,
} from 'typeorm';
import { Project } from './project';
import { QfRound } from './qfRound';

@Entity('project_qf_rounds_qf_round')
@Entity('project_qf_rounds_qf_round', { synchronize: false })
@ObjectType()
@Unique(['projectId', 'qfRoundId']) // Ensure uniqueness of the composite key
export class ProjectQfRound extends BaseEntity {
@Field(_type => ID)
@Column({ generated: 'increment' })
@Index()
@PrimaryGeneratedColumn() // Make this the primary key
id: number;

@Field(_type => ID)
@PrimaryColumn()
@Column()
@Index()
projectId: number;

@Field(_type => ID)
@PrimaryColumn()
@Column()
@Index()
qfRoundId: number;

@ManyToOne(_type => Project, project => project.projectQfRoundRelations)
Expand Down
Loading