Skip to content

Commit

Permalink
Fix datamodel constraint and rename puid to projects_pu_id
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Sep 25, 2023
1 parent 069232c commit 5c59b9f
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddCostSurdaceApiDb1691980238543 implements MigrationInterface {
export class AddCostSurfaceApiDb1691980238543 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE cost_surfaces (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export class SetProjectGridFromShapefileHandler
);
await Promise.all(
puIds.map((puid) =>
costSurfaceRepository.update({ puid }, { costSurfaceId }),
costSurfaceRepository.update(
{ projectsPuId: puid },
{ costSurfaceId },
),
),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ export class AddsCostSurfacePuDataGeoDb1692254627921
await queryRunner.query(`
CREATE TABLE cost_surface_pu_data (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
-- consider marking this as not null, as it is for projects, and maybe required for the GC
cost_surface_id uuid NOT NULL,
puid uuid NOT NULL REFERENCES projects_pu(id) ON DELETE CASCADE,
projects_pu_id uuid NOT NULL REFERENCES projects_pu(id) ON DELETE CASCADE,
cost float8 NOT NULL,
-- modifying this as I need the change for tests
UNIQUE (cost_surface_id, puid)
UNIQUE (cost_surface_id, projects_pu_id)
);
`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class TypeormProjectCostSurface
CostSurfacePuDataEntity,
rows.map((row) => ({
cost: row.cost,
puid: row.puid,
puid: row.projectsPuId,
costSurfaceId: row.costSurfaceId,
})),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class ProjectCostSurfaceProcessor
costSurfaces.map(
(record) =>
({
puid: projectPlanningUnitsByPuid[record.puid],
projectsPuId: projectPlanningUnitsByPuid[record.puid],
cost: record.cost,
costSurfaceId: job.data.costSurfaceId,
} as CostSurfacePuDataEntity),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('planning units jobs (e2e)', () => {
},
});
const costPus = await costPuDataRepo.find({
where: { puid: In(projectPus.map((pu) => pu.id)) },
where: { projectsPuId: In(projectPus.map((pu) => pu.id)) },
});

expect(projectPus.length).toBeGreaterThan(0);
Expand Down
9 changes: 3 additions & 6 deletions api/libs/cost-surfaces/src/cost-surface-pu-data.geo.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ export class CostSurfacePuDataEntity {
() => ProjectsPuEntity,
(projectsPu: ProjectsPuEntity) => projectsPu.id,
)
@JoinColumn({ name: 'puid' })
@JoinColumn({ name: 'projects_pu_id' })
projectsPu?: ProjectsPuEntity;

@Column({ type: 'uuid', name: 'puid' })
/**
* @todo: Naming feels a bit confusing. The tasks states that this sould be a relation to ProjectsPu.id, however there are more entities with the puid column referecing planning_units
*/
puid!: string;
@Column({ type: 'uuid', name: 'projects_pu_id' })
projectsPuId!: string;

@Column({ type: 'float8' }) // Matching TypeORM type for float8
cost!: number;
Expand Down

0 comments on commit 5c59b9f

Please sign in to comment.