diff --git a/migration/1728554628004-AddEstimatedClusterMatching.ts b/migration/1728554628004-AddEstimatedClusterMatching.ts new file mode 100644 index 000000000..a31ab2617 --- /dev/null +++ b/migration/1728554628004-AddEstimatedClusterMatching.ts @@ -0,0 +1,34 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class AddEstimatedClusterMatching1728554628004 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + CREATE TABLE estimated_cluster_matching ( + id SERIAL PRIMARY KEY, + project_id INT NOT NULL, + qf_round_id INT NOT NULL, + matching DOUBLE PRECISION NOT NULL + ); + `); + + // Create indexes on the new table + await queryRunner.query(` + CREATE INDEX estimated_cluster_matching_project_id_qfround_id + ON estimated_cluster_matching (project_id, qf_round_id); + `); + + await queryRunner.query(` + CREATE INDEX estimated_cluster_matching_matching + ON estimated_cluster_matching (matching); + `); + } + + public async down(queryRunner: QueryRunner): Promise { + // Revert changes if necessary by dropping the table and restoring the view + await queryRunner.query(` + DROP TABLE IF EXISTS estimated_cluster_matching; + `); + } + +} diff --git a/src/entities/estimatedClusterMatching.ts b/src/entities/estimatedClusterMatching.ts new file mode 100644 index 000000000..da2165e8e --- /dev/null +++ b/src/entities/estimatedClusterMatching.ts @@ -0,0 +1,41 @@ +import { Field, ObjectType } from 'type-graphql'; +import { + Column, + Index, + PrimaryGeneratedColumn, + BaseEntity, + Entity, + ManyToOne, + JoinColumn, +} from 'typeorm'; +import { Project } from './project'; + +@Entity('estimated_cluster_matching') +@Index('estimated_cluster_matching_project_id_qfround_id', [ + 'projectId', + 'qfRoundId', +]) +@Index('estimated_cluster_matching_matching', ['matching']) +@ObjectType() +export class EstimatedClusterMatching extends BaseEntity { + @Field() + @PrimaryGeneratedColumn() + id: number; // New primary key + + @Field(_type => Project) + @ManyToOne(_type => Project, project => project.projectEstimatedMatchingView) + @JoinColumn({ referencedColumnName: 'id' }) + project: Project; + + @Field() + @Column() + projectId: number; + + @Field() + @Column() + qfRoundId: number; + + @Field() + @Column('double precision') + matching: number; +}