From 9b74678a794689dfb5408a94b12c67ef71c47edc Mon Sep 17 00:00:00 2001 From: Fabien Tafforeau Date: Wed, 15 Jan 2025 22:18:37 +0100 Subject: [PATCH] Revert "feat: delete position inconnue (#502)" (#503) This reverts commit fd950fab93943a1cb947e43f247c06cdde385201. --- Procfile | 2 +- apps/api/src/lib/utils/csv.utils.ts | 2 +- .../dto/update_batch_numero_change.dto.ts | 3 - apps/api/test/base_locale.e2e-spec.ts | 6 +- apps/api/test/numero.e2e-spec.ts | 2 +- apps/api/test/publication.e2e-spec.ts | 8 +-- apps/api/test/toponyme.e2e-spec.ts | 2 +- apps/cron/test/task.e2e-spec.ts | 6 +- libs/shared/src/entities/position.entity.ts | 3 +- .../1736244568004-delete_position_inconnue.ts | 65 ------------------- scripts/postdeploy.sh | 3 - 11 files changed, 15 insertions(+), 87 deletions(-) delete mode 100644 migrations/1736244568004-delete_position_inconnue.ts delete mode 100644 scripts/postdeploy.sh diff --git a/Procfile b/Procfile index 17c57942..bf1ea7eb 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ clock: yarn start:cron -postdeploy: bash scripts/postdeploy.sh \ No newline at end of file +postdeploy: yarn typeorm:migration:run \ No newline at end of file diff --git a/apps/api/src/lib/utils/csv.utils.ts b/apps/api/src/lib/utils/csv.utils.ts index e6d9e798..a0a8a3e1 100644 --- a/apps/api/src/lib/utils/csv.utils.ts +++ b/apps/api/src/lib/utils/csv.utils.ts @@ -57,7 +57,7 @@ export function extractCodeCommune({ function extractPosition(row: any) { return { source: row.parsedValues.source || null, - type: row.parsedValues.position || PositionTypeEnum.ENTREE, + type: row.parsedValues.position || PositionTypeEnum.INCONNUE, point: { type: 'Point', coordinates: [row.parsedValues.long, row.parsedValues.lat], diff --git a/apps/api/src/modules/numeros/dto/update_batch_numero_change.dto.ts b/apps/api/src/modules/numeros/dto/update_batch_numero_change.dto.ts index f5f27f5e..f9034b80 100644 --- a/apps/api/src/modules/numeros/dto/update_batch_numero_change.dto.ts +++ b/apps/api/src/modules/numeros/dto/update_batch_numero_change.dto.ts @@ -6,11 +6,9 @@ import { IsNotEmpty, IsMongoId, ValidateIf, - Validate, } from 'class-validator'; import { PositionTypeEnum } from '@/shared/entities/position.entity'; -import { ValidatorBal } from '@/shared/validators/validator_bal.validator'; export class UpdateBatchNumeroChangeDTO { @IsOptional() @@ -33,7 +31,6 @@ export class UpdateBatchNumeroChangeDTO { @IsOptional() @IsNotEmpty() @IsEnum(PositionTypeEnum) - @Validate(ValidatorBal, ['position']) @ApiProperty({ required: false, nullable: false }) positionType?: PositionTypeEnum; diff --git a/apps/api/test/base_locale.e2e-spec.ts b/apps/api/test/base_locale.e2e-spec.ts index 25d321b2..edcae4cb 100644 --- a/apps/api/test/base_locale.e2e-spec.ts +++ b/apps/api/test/base_locale.e2e-spec.ts @@ -187,7 +187,7 @@ describe('BASE LOCAL MODULE', () => { }; return { id, - type: PositionTypeEnum.ENTREE, + type: PositionTypeEnum.INCONNUE, source: 'ban', point, } as Position; @@ -579,8 +579,8 @@ describe('BASE LOCAL MODULE', () => { 'text/csv; charset=utf-8', ); const csvFile = `cle_interop;id_ban_commune;id_ban_toponyme;id_ban_adresse;voie_nom;lieudit_complement_nom;numero;suffixe;certification_commune;commune_insee;commune_nom;position;long;lat;x;y;cad_parcelles;source;date_der_maj - 91534_xxxx_00001_bis;${communeUuid};${voieUuid1};${numeroUuid1};rue de la paix;allée;1;bis;1;91534;Saclay;entrée;8;42;1114835.92;6113076.85;;ban;2000-01-02 - 91534_xxxx_00001_ter;${communeUuid};${voieUuid2};${numeroUuid2};rue de paris;allée;1;ter;0;91534;Saclay;entrée;8;42;1114835.92;6113076.85;;ban;2000-01-02 + 91534_xxxx_00001_bis;${communeUuid};${voieUuid1};${numeroUuid1};rue de la paix;allée;1;bis;1;91534;Saclay;inconnue;8;42;1114835.92;6113076.85;;ban;2000-01-02 + 91534_xxxx_00001_ter;${communeUuid};${voieUuid2};${numeroUuid2};rue de paris;allée;1;ter;0;91534;Saclay;inconnue;8;42;1114835.92;6113076.85;;ban;2000-01-02 91534_xxxx_99999;${communeUuid};${toponymeUuid1};;allée;;99999;;;91534;Saclay;;;;;;;commune;2000-01-02`; expect(response.text.replace(/\s/g, '')).toEqual( csvFile.replace(/\s/g, ''), diff --git a/apps/api/test/numero.e2e-spec.ts b/apps/api/test/numero.e2e-spec.ts index 69ea5ba5..c1bcd2fa 100644 --- a/apps/api/test/numero.e2e-spec.ts +++ b/apps/api/test/numero.e2e-spec.ts @@ -402,7 +402,7 @@ describe('NUMERO', () => { positions: [ { id: new ObjectId().toHexString(), - type: PositionTypeEnum.ENTREE, + type: PositionTypeEnum.INCONNUE, source: 'ban', point: { type: 'Point', diff --git a/apps/api/test/publication.e2e-spec.ts b/apps/api/test/publication.e2e-spec.ts index 73a73284..76290366 100644 --- a/apps/api/test/publication.e2e-spec.ts +++ b/apps/api/test/publication.e2e-spec.ts @@ -159,7 +159,7 @@ describe('PUBLICATION MODULE', () => { }; return { id, - type: PositionTypeEnum.ENTREE, + type: PositionTypeEnum.INCONNUE, source: 'ban', point, } as Position; @@ -225,7 +225,7 @@ describe('PUBLICATION MODULE', () => { axiosMock.onPost(`/revisions/${revisionId}/compute`).reply(200, revision); const csvFile = `cle_interop;id_ban_commune;id_ban_toponyme;id_ban_adresse;voie_nom;lieudit_complement_nom;numero;suffixe;certification_commune;commune_insee;commune_nom;position;long;lat;x;y;cad_parcelles;source;date_der_maj - 91534_xxxx_00001_bis;${communeUuid};${voieUuid};${numeroUuid};rue de la paix;;1;bis;1;91534;Saclay;entrée;8;42;1114835.92;6113076.85;;ban;2000-01-01`; + 91534_xxxx_00001_bis;${communeUuid};${voieUuid};${numeroUuid};rue de la paix;;1;bis;1;91534;Saclay;inconnue;8;42;1114835.92;6113076.85;;ban;2000-01-01`; axiosMock .onPut(`/revisions/${revisionId}/files/bal`) .reply(({ data }) => { @@ -346,7 +346,7 @@ describe('PUBLICATION MODULE', () => { axiosMock.onPost(`/revisions/${revisionId}/compute`).reply(200, revision); const csvFile = `cle_interop;id_ban_commune;id_ban_toponyme;id_ban_adresse;voie_nom;lieudit_complement_nom;numero;suffixe;certification_commune;commune_insee;commune_nom;position;long;lat;x;y;cad_parcelles;source;date_der_maj - 91534_xxxx_00001_bis;${communeUuid};${toponymeUuid};${numeroUuid};rue de la paix;;1;bis;1;91534;Saclay;entrée;8;42;1114835.92;6113076.85;;ban;2000-01-01`; + 91534_xxxx_00001_bis;${communeUuid};${toponymeUuid};${numeroUuid};rue de la paix;;1;bis;1;91534;Saclay;inconnue;8;42;1114835.92;6113076.85;;ban;2000-01-01`; axiosMock .onPut(`/revisions/${revisionId}/files/bal`) .reply(({ data }) => { @@ -409,7 +409,7 @@ describe('PUBLICATION MODULE', () => { files: [ { type: 'bal', - hash: '8e23f1782299e8d5970c1fa800a7074beaac7eeac4c1f0c484e4f6441f680011', + hash: '0c5d808a7e5612c9467607c574cb2317a76fe04d493efbd61b55a31bbd194227', }, ], }; diff --git a/apps/api/test/toponyme.e2e-spec.ts b/apps/api/test/toponyme.e2e-spec.ts index 06bcaad2..c324ae42 100644 --- a/apps/api/test/toponyme.e2e-spec.ts +++ b/apps/api/test/toponyme.e2e-spec.ts @@ -158,7 +158,7 @@ describe('TOPONYME MODULE', () => { }; return { id, - type: PositionTypeEnum.ENTREE, + type: PositionTypeEnum.INCONNUE, source: 'ban', point, } as Position; diff --git a/apps/cron/test/task.e2e-spec.ts b/apps/cron/test/task.e2e-spec.ts index b1c5e765..e4ffa141 100644 --- a/apps/cron/test/task.e2e-spec.ts +++ b/apps/cron/test/task.e2e-spec.ts @@ -208,7 +208,7 @@ describe('TASK MODULE', () => { }; return { id, - type: PositionTypeEnum.ENTREE, + type: PositionTypeEnum.INCONNUE, source: 'ban', point, } as Position; @@ -370,7 +370,7 @@ describe('TASK MODULE', () => { axiosMock.onPost(`/revisions/${revisionId}/compute`).reply(200, revision); const csvFile = `cle_interop;id_ban_commune;id_ban_toponyme;id_ban_adresse;voie_nom;lieudit_complement_nom;numero;suffixe;certification_commune;commune_insee;commune_nom;position;long;lat;x;y;cad_parcelles;source;date_der_maj - 91534_xxxx_00001_bis;52c4de09-6b82-45eb-8ed7-b212607282f7;26734c2d-2a14-4eeb-ac5b-1be055c0a5ae;2da3bb47-1a10-495a-8c29-6b8d0e79f9af;rue de la paix;;1;bis;1;91534;Saclay;entrée;8;42;1114835.92;6113076.85;;ban;2000-01-01`; + 91534_xxxx_00001_bis;52c4de09-6b82-45eb-8ed7-b212607282f7;26734c2d-2a14-4eeb-ac5b-1be055c0a5ae;2da3bb47-1a10-495a-8c29-6b8d0e79f9af;rue de la paix;;1;bis;1;91534;Saclay;inconnue;8;42;1114835.92;6113076.85;;ban;2000-01-01`; axiosMock.onPut(`/revisions/${revisionId}/files/bal`).reply(({ data }) => { expect(data.replace(/\s/g, '')).toEqual(csvFile.replace(/\s/g, '')); return [200, null]; @@ -425,7 +425,7 @@ describe('TASK MODULE', () => { files: [ { type: 'bal', - hash: '5a9646ce4fe552b0dc619e166b0ce7968fa34c94e634331b090452a26c888f7d', + hash: 'a62492c9dbd6c74e7cfb2b67b3a9e49be89da7b8fa4dff3c061b0f82805b65c9', }, ], }; diff --git a/libs/shared/src/entities/position.entity.ts b/libs/shared/src/entities/position.entity.ts index 2b1f1c74..dceaa42c 100644 --- a/libs/shared/src/entities/position.entity.ts +++ b/libs/shared/src/entities/position.entity.ts @@ -14,7 +14,6 @@ import { Toponyme } from './toponyme.entity'; import { ObjectId } from 'mongodb'; import { Validate } from 'class-validator'; import { PointValidator } from '../validators/coord.validator'; -import { ValidatorBal } from '../validators/validator_bal.validator'; export enum PositionTypeEnum { ENTREE = 'entrée', @@ -25,6 +24,7 @@ export enum PositionTypeEnum { DELIVRANCE_POSTALE = 'délivrance postale', PARCELLE = 'parcelle', SEGMENT = 'segment', + INCONNUE = 'inconnue', } @Entity({ name: 'positions' }) @@ -49,7 +49,6 @@ export class Position { numeroId?: string; @ApiProperty({ enum: PositionTypeEnum }) - @Validate(ValidatorBal, ['position']) @Column('enum', { enum: PositionTypeEnum, default: PositionTypeEnum.ENTREE, diff --git a/migrations/1736244568004-delete_position_inconnue.ts b/migrations/1736244568004-delete_position_inconnue.ts deleted file mode 100644 index 1ad3fe9c..00000000 --- a/migrations/1736244568004-delete_position_inconnue.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; - -export class DeletePositionInconnue1736244568004 implements MigrationInterface { - name = 'DeletePositionInconnue1736244568004'; - - private async queryPositionTypeToEntree(queryRunner: QueryRunner, limit) { - return await queryRunner.query( - `WITH updated_rows AS ( - SELECT id - FROM positions - WHERE type = 'inconnue' - LIMIT ${limit} - ) - UPDATE positions - SET type = 'entrée' - WHERE id IN (SELECT id FROM updated_rows);`, - ); - } - - public async up(queryRunner: QueryRunner): Promise { - const limit = 10000; - let count = 0; - let res = await this.queryPositionTypeToEntree(queryRunner, limit); - while (res[1] >= limit) { - count += res[1]; - console.log(`COUNT ${count}`); - res = await this.queryPositionTypeToEntree(queryRunner, limit); - } - await queryRunner.query( - `ALTER TYPE "public"."positions_type_enum" RENAME TO "positions_type_enum_old"`, - ); - await queryRunner.query( - `CREATE TYPE "public"."positions_type_enum" AS ENUM('entrée', 'bâtiment', 'cage d’escalier', 'logement', 'service technique', 'délivrance postale', 'parcelle', 'segment')`, - ); - await queryRunner.query( - `ALTER TABLE "positions" ALTER COLUMN "type" DROP DEFAULT`, - ); - await queryRunner.query( - `ALTER TABLE "positions" ALTER COLUMN "type" TYPE "public"."positions_type_enum" USING "type"::"text"::"public"."positions_type_enum"`, - ); - await queryRunner.query( - `ALTER TABLE "positions" ALTER COLUMN "type" SET DEFAULT 'entrée'`, - ); - await queryRunner.query(`DROP TYPE "public"."positions_type_enum_old"`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query( - `CREATE TYPE "public"."positions_type_enum_old" AS ENUM('entrée', 'bâtiment', 'cage d’escalier', 'logement', 'service technique', 'délivrance postale', 'parcelle', 'segment', 'inconnue')`, - ); - await queryRunner.query( - `ALTER TABLE "positions" ALTER COLUMN "type" DROP DEFAULT`, - ); - await queryRunner.query( - `ALTER TABLE "positions" ALTER COLUMN "type" TYPE "public"."positions_type_enum_old" USING "type"::"text"::"public"."positions_type_enum_old"`, - ); - await queryRunner.query( - `ALTER TABLE "positions" ALTER COLUMN "type" SET DEFAULT 'entrée'`, - ); - await queryRunner.query(`DROP TYPE "public"."positions_type_enum"`); - await queryRunner.query( - `ALTER TYPE "public"."positions_type_enum_old" RENAME TO "positions_type_enum"`, - ); - } -} diff --git a/scripts/postdeploy.sh b/scripts/postdeploy.sh deleted file mode 100644 index 7121f362..00000000 --- a/scripts/postdeploy.sh +++ /dev/null @@ -1,3 +0,0 @@ -if [ $LAUNCH_MIGRATION_AT_START = "true" ] ; then - exec yarn typeorm:migration:run -fi \ No newline at end of file