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

fix: delete position type inconnue #496

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
clock: yarn start:cron
postdeploy: yarn typeorm:migration:run
clock: yarn start:cron
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On pourrait pas se servir d'une variable d'env pour lancer les migrations en mode auto ou non?
Je vois dans la doc de Scalingo qu'on peut faire ce genre de chose : https://doc.scalingo.com/platform/app/procfile

Le Procfile :
clock: yarn start:cron
postdeploy: bash bin/postdeploy.sh

et le script postdeploy.sh =>
#!/bin/bash

if [ "$LAUNCH_MIGRATION_AT_START" = "true" ] ; then
exec yarn typeorm:migration:run
fi

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je suis pas très fan de la solution mais c'est peut être mieux que a l'heure actuelle

2 changes: 1 addition & 1 deletion apps/api/src/lib/utils/csv.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function extractCodeCommune({
function extractPosition(row: any) {
return {
source: row.parsedValues.source || null,
type: row.parsedValues.position || PositionTypeEnum.INCONNUE,
type: row.parsedValues.position || PositionTypeEnum.ENTREE,
point: {
type: 'Point',
coordinates: [row.parsedValues.long, row.parsedValues.lat],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ 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()
Expand All @@ -31,6 +33,7 @@ export class UpdateBatchNumeroChangeDTO {
@IsOptional()
@IsNotEmpty()
@IsEnum(PositionTypeEnum)
@Validate(ValidatorBal, ['position'])
@ApiProperty({ required: false, nullable: false })
positionType?: PositionTypeEnum;

Expand Down
6 changes: 3 additions & 3 deletions apps/api/test/base_locale.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('BASE LOCAL MODULE', () => {
};
return {
id,
type: PositionTypeEnum.INCONNUE,
type: PositionTypeEnum.ENTREE,
source: 'ban',
point,
} as Position;
Expand Down Expand Up @@ -578,8 +578,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;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_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_99999;${communeUuid};${toponymeUuid1};;allée;;99999;;;91534;Saclay;;;;;;;commune;2000-01-02`;
expect(response.text.replace(/\s/g, '')).toEqual(
csvFile.replace(/\s/g, ''),
Expand Down
2 changes: 1 addition & 1 deletion apps/api/test/numero.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ describe('NUMERO', () => {
positions: [
{
id: new ObjectId().toHexString(),
type: PositionTypeEnum.INCONNUE,
type: PositionTypeEnum.ENTREE,
source: 'ban',
point: {
type: 'Point',
Expand Down
8 changes: 4 additions & 4 deletions apps/api/test/publication.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('PUBLICATION MODULE', () => {
};
return {
id,
type: PositionTypeEnum.INCONNUE,
type: PositionTypeEnum.ENTREE,
source: 'ban',
point,
} as Position;
Expand Down Expand Up @@ -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;inconnue;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;entrée;8;42;1114835.92;6113076.85;;ban;2000-01-01`;
axiosMock
.onPut(`/revisions/${revisionId}/files/bal`)
.reply(({ data }) => {
Expand Down Expand Up @@ -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;inconnue;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;entrée;8;42;1114835.92;6113076.85;;ban;2000-01-01`;
axiosMock
.onPut(`/revisions/${revisionId}/files/bal`)
.reply(({ data }) => {
Expand Down Expand Up @@ -409,7 +409,7 @@ describe('PUBLICATION MODULE', () => {
files: [
{
type: 'bal',
hash: '0c5d808a7e5612c9467607c574cb2317a76fe04d493efbd61b55a31bbd194227',
hash: '8e23f1782299e8d5970c1fa800a7074beaac7eeac4c1f0c484e4f6441f680011',
},
],
};
Expand Down
2 changes: 1 addition & 1 deletion apps/api/test/toponyme.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('TOPONYME MODULE', () => {
};
return {
id,
type: PositionTypeEnum.INCONNUE,
type: PositionTypeEnum.ENTREE,
source: 'ban',
point,
} as Position;
Expand Down
6 changes: 3 additions & 3 deletions apps/cron/test/task.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('TASK MODULE', () => {
};
return {
id,
type: PositionTypeEnum.INCONNUE,
type: PositionTypeEnum.ENTREE,
source: 'ban',
point,
} as Position;
Expand Down Expand Up @@ -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;inconnue;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;entrée;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];
Expand Down Expand Up @@ -425,7 +425,7 @@ describe('TASK MODULE', () => {
files: [
{
type: 'bal',
hash: 'a62492c9dbd6c74e7cfb2b67b3a9e49be89da7b8fa4dff3c061b0f82805b65c9',
hash: '5a9646ce4fe552b0dc619e166b0ce7968fa34c94e634331b090452a26c888f7d',
},
],
};
Expand Down
3 changes: 2 additions & 1 deletion libs/shared/src/entities/position.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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',
Expand All @@ -24,7 +25,6 @@ export enum PositionTypeEnum {
DELIVRANCE_POSTALE = 'délivrance postale',
PARCELLE = 'parcelle',
SEGMENT = 'segment',
INCONNUE = 'inconnue',
}

@Entity({ name: 'positions' })
Expand All @@ -49,6 +49,7 @@ export class Position {
numeroId?: string;

@ApiProperty({ enum: PositionTypeEnum })
@Validate(ValidatorBal, ['position'])
@Column('enum', {
enum: PositionTypeEnum,
default: PositionTypeEnum.ENTREE,
Expand Down
46 changes: 46 additions & 0 deletions migrations/1736244568004-delete_position_inconnue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class DeletePositionInconnue1736244568004 implements MigrationInterface {
name = 'DeletePositionInconnue1736244568004';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`UPDATE positions SET type = 'entrée' WHERE type = 'inconnue'`,
);
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<void> {
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'`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pour le down, il faudrait set le default à "inconnue"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ça me parait compliqué toutes ces manipulations de l'enum... Y'a pas juste moyen de supprimer / ajouter une valeur dans l'enum?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alors pour la première remarque, le type par DEFAULT est deja entrée avant la migration
Ensuite il existe une commande postgres pour ADD VALUE mais pas pour DROP VALUE https://www.postgresql.org/docs/14/sql-altertype.html, j'ai quand même essayé en local (dans le doute) la commande DROP VALUE et ca n'existe pas

);
await queryRunner.query(`DROP TYPE "public"."positions_type_enum"`);
await queryRunner.query(
`ALTER TYPE "public"."positions_type_enum_old" RENAME TO "positions_type_enum"`,
);
}
}
Loading