Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: project/scenario/feature linking #945

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class CreateFeaturesUniqueIndexes1648640687600
implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`
CREATE UNIQUE INDEX unique_platform_features ON features (feature_class_name) WHERE project_id IS NULL;
`);

await queryRunner.query(`
CREATE UNIQUE INDEX unique_project_features ON features (feature_class_name, project_id) WHERE project_id IS NOT NULL;
`);
}

async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`
DROP INDEX unique_platform_features;
`);
await queryRunner.query(`
DROP INDEX unique_project_features;
`);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddProjectsPuPlanningAreaIdColumn1648641020335
implements MigrationInterface {
readonly defaultGeometry =
'0103000020E610000001000000050000000000000088022BC01596661D3B4C3D4000000000EE232BC0F2A7E0E25C3B3D4000000000C2132BC0A1A5CF4A3B333D4000000000D3E42AC02875DF6406453D400000000088022BC01596661D3B4C3D40';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
UPDATE features_data
SET the_geom = '${this.defaultGeometry}'
WHERE the_geom IS NULL
`);

await queryRunner.query(`
ALTER TABLE features_data
ALTER COLUMN the_geom SET NOT NULL;
`);

await queryRunner.query(`
ALTER TABLE features_data
ADD COLUMN hash TEXT NOT NULL GENERATED ALWAYS AS (md5(the_geom::bytea::text || coalesce(properties, '{}')::text)) STORED;
`);
await queryRunner.query(`
CREATE UNIQUE INDEX unique_feature_data_per_project ON features_data(hash, feature_id);
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE features_data
ALTER COLUMN the_geom DROP NOT NULL
`);

await queryRunner.query(`
ALTER TABLE features_data DROP COLUMN hash;
`);
await queryRunner.query(`
DROP INDEX unique_feature_data_per_project;
`);
}
}
Original file line number Diff line number Diff line change
@@ -4,13 +4,13 @@ import {
blmSandboxRunner,
} from '@marxan-geoprocessing/marxan-sandboxed-runner/adapters-blm/blm-run-adapter.module';
import { MarxanSandboxBlmRunnerService } from '@marxan-geoprocessing/marxan-sandboxed-runner/adapters-blm/marxan-sandbox-blm-runner.service';
import { GeoFeatureGeometry } from '@marxan/geofeatures';
import {
PlanningUnitsGeom,
ProjectsPuEntity,
} from '@marxan-jobs/planning-unit-geometry';
import { BlmFinalResultEntity } from '@marxan/blm-calibration';
import { FeatureTag, ScenarioFeaturesData } from '@marxan/features';
import { GeoFeatureGeometry } from '@marxan/geofeatures';
import {
ExecutionResult,
MarxanExecutionMetadataGeoEntity,
@@ -19,6 +19,7 @@ import {
} from '@marxan/marxan-output';
import { getEntityManagerToken, getRepositoryToken } from '@nestjs/typeorm';
import { readFileSync } from 'fs';
import { Geometry } from 'geojson';
import { last } from 'lodash';
import * as nock from 'nock';
import { EntityManager, In, Repository } from 'typeorm';
@@ -102,6 +103,7 @@ const NUMBER_OF_RUNS = 100;
const getFixtures = async () => {
const projectId = v4();
const scenarioId = v4();
const featureId = v4();
const outputsIds: string[] = [];
const scenarioFeatures: string[] = [];

@@ -160,8 +162,8 @@ const getFixtures = async () => {
id: In(projectPus.map((pu) => pu.geomId)),
});

await scenarioFeatureRepo.delete({
scenarioId,
await featuresData.delete({
featureId,
});
await blmFinalResultsRepo.delete({
scenarioId,
@@ -211,7 +213,21 @@ const getFixtures = async () => {
GivenScenarioDataExists: async () => {
const feature = await featuresData.save(
featuresData.create({
featureId: v4(),
featureId,
properties: {
foo: v4(),
},
theGeom: {
type: 'Polygon',
coordinates: [
[
[-3.7023925781249996, 40.657722371758105],
[-4.3450927734375, 40.029717557833266],
[-3.04046630859375, 39.9434364619742],
[-3.7023925781249996, 40.657722371758105],
],
],
},
}),
);
scenarioFeatures.push(
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ import { PromiseType } from 'utility-types';
import { v4 } from 'uuid';
import { GivenScenarioPuData } from '../../steps/given-scenario-pu-data-exists';
import { bootstrapApplication, delay } from '../../utils';
import { Geometry } from 'geojson';

let fixtures: PromiseType<ReturnType<typeof getFixtures>>;

@@ -101,6 +102,7 @@ const NUMBER_OF_RUNS = 100;
const getFixtures = async () => {
const projectId = v4();
const scenarioId = v4();
const featureId = v4();
const outputsIds: string[] = [];
const scenarioFeatures: string[] = [];

@@ -144,8 +146,8 @@ const getFixtures = async () => {
scenarioId,
});
await puOutputRepo.delete({});
await scenarioFeatureRepo.delete({
scenarioId,
await featuresData.delete({
featureId,
});
const projectPus = await entityManager.find(ProjectsPuEntity, {
where: { projectId },
@@ -197,7 +199,21 @@ const getFixtures = async () => {
GivenScenarioDataExists: async () => {
const feature = await featuresData.save(
featuresData.create({
featureId: v4(),
featureId,
properties: {
foo: v4(),
},
theGeom: {
type: 'Polygon',
coordinates: [
[
[-3.7023925781249996, 40.657722371758105],
[-4.3450927734375, 40.029717557833266],
[-3.04046630859375, 39.9434364619742],
[-3.7023925781249996, 40.657722371758105],
],
],
},
}),
);
scenarioFeatures.push(