Skip to content

Commit

Permalink
add cluster matching entity
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed Oct 10, 2024
1 parent 046b6e8 commit b20f60d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
34 changes: 34 additions & 0 deletions migration/1728554628004-AddEstimatedClusterMatching.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class AddEstimatedClusterMatching1728554628004 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
// Revert changes if necessary by dropping the table and restoring the view
await queryRunner.query(`
DROP TABLE IF EXISTS estimated_cluster_matching;
`);
}

}
41 changes: 41 additions & 0 deletions src/entities/estimatedClusterMatching.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit b20f60d

Please sign in to comment.