Skip to content

Commit

Permalink
fix(bordeaux): add 'npai''
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Oct 10, 2023
1 parent 81b77ef commit 5343c5f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/backend/src/_migrations/1696941100775-manual-migration.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {
//
}
}

0 comments on commit 5343c5f

Please sign in to comment.