From 5343c5f6f86e3d5b56675d5af59f9beb213c093a Mon Sep 17 00:00:00 2001 From: Yassine R Date: Tue, 10 Oct 2023 15:18:10 +0200 Subject: [PATCH] fix(bordeaux): add 'npai'' --- .../1696941100775-manual-migration.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 packages/backend/src/_migrations/1696941100775-manual-migration.ts diff --git a/packages/backend/src/_migrations/1696941100775-manual-migration.ts b/packages/backend/src/_migrations/1696941100775-manual-migration.ts new file mode 100644 index 0000000000..10c8f47ad0 --- /dev/null +++ b/packages/backend/src/_migrations/1696941100775-manual-migration.ts @@ -0,0 +1,39 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; +import { usagerRepository } from "../database"; +import { appLogger } from "../util"; + +export class ManualMigration1696941100775 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + const condition = `("options"->'npai'->>'actif')::boolean is false and decision->>'statut' = 'RADIE' and "structureId" = 201 and decision->>'dateDebut' < '2023-06-01'`; + const before: number = await usagerRepository + .createQueryBuilder("usager") + .select("COUNT(uuid)") + .where(condition) + .getCount(); + + appLogger.info( + "[MIGRATION] Mise à jour des 'NPAI' pour les radiés de Bordeaux ..." + ); + appLogger.info("Avant la migration: " + before); + + await queryRunner.query( + `UPDATE usager SET "options" = jsonb_set("options", '{npai,actif}', 'true', false) WHERE ("options"->'npai'->>'actif')::boolean is false AND decision->>'statut' = 'RADIE' AND "structureId" = 201 AND decision->>'dateDebut' < '2023-06-01'` + ); + + const after: number = await usagerRepository + .createQueryBuilder("usager") + .select("COUNT(uuid)") + .where(condition) + .getCount(); + + appLogger.info("Après la migration: " + after); + appLogger.info( + "[MIGRATION] Mise à jour des 'NPAI' pour les radiés de Bordeaux ✅" + ); + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public async down(_queryRunner: QueryRunner): Promise { + // + } +}