From 3ba9d6570e79839c413fc8fc01a59f45c4e12b9d Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 8 Oct 2025 22:34:01 +0200 Subject: [PATCH 1/2] fix projectQfRound entity --- .../1779182511002-FixProjectQfRoundsPrimaryKey.ts | 8 ++++++++ src/entities/projectQfRound.ts | 13 ++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/migration/1779182511002-FixProjectQfRoundsPrimaryKey.ts b/migration/1779182511002-FixProjectQfRoundsPrimaryKey.ts index 40c37543f..ed2bfd1ea 100644 --- a/migration/1779182511002-FixProjectQfRoundsPrimaryKey.ts +++ b/migration/1779182511002-FixProjectQfRoundsPrimaryKey.ts @@ -6,6 +6,10 @@ export class FixProjectQfRoundsPrimaryKey1779182511002 name = 'FixProjectQfRoundsPrimaryKey1779182511002'; public async up(queryRunner: QueryRunner): Promise { + // 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 @@ -267,6 +271,10 @@ export class FixProjectQfRoundsPrimaryKey1779182511002 } public async down(queryRunner: QueryRunner): Promise { + // 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" diff --git a/src/entities/projectQfRound.ts b/src/entities/projectQfRound.ts index 55d2a4593..1c3489ec1 100644 --- a/src/entities/projectQfRound.ts +++ b/src/entities/projectQfRound.ts @@ -1,6 +1,6 @@ import { Field, ID, ObjectType, Float, Int } from 'type-graphql'; import { - PrimaryColumn, + PrimaryGeneratedColumn, Column, Entity, ManyToOne, @@ -8,24 +8,27 @@ import { CreateDateColumn, UpdateDateColumn, Index, + Unique, } from 'typeorm'; import { Project } from './project'; import { QfRound } from './qfRound'; @Entity('project_qf_rounds_qf_round') @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) From 4c5de91c1df6fd48e86ed6165dadafa5f8cd1f32 Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 9 Oct 2025 14:52:32 +0200 Subject: [PATCH 2/2] unsync the table --- src/entities/project.ts | 2 +- src/entities/projectQfRound.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/entities/project.ts b/src/entities/project.ts index 41e920b7c..b7fa9191e 100644 --- a/src/entities/project.ts +++ b/src/entities/project.ts @@ -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 }) diff --git a/src/entities/projectQfRound.ts b/src/entities/projectQfRound.ts index 1c3489ec1..c77686cc3 100644 --- a/src/entities/projectQfRound.ts +++ b/src/entities/projectQfRound.ts @@ -13,7 +13,7 @@ import { 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 {