-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
142 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
26 changes: 13 additions & 13 deletions
26
_scripts/db/dumps/domifa_test.postgres.restore-data-only.sql
Large diffs are not rendered by default.
Oops, something went wrong.
26 changes: 13 additions & 13 deletions
26
_scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql
Large diffs are not rendered by default.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
packages/backend/src/_migrations/1704813167013-manual-migration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class ManualMigration1704813167013 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`update usager_history set migrated = false`); | ||
} | ||
|
||
public async down(_queryRunner: QueryRunner): Promise<void> { | ||
// | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
packages/backend/src/_migrations/1704813169210-update-end-date-migration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { In, MigrationInterface, QueryRunner } from "typeorm"; | ||
import { UsagerHistory, UsagerHistoryState } from "../_common/model"; | ||
import { usagerHistoryRepository } from "../database"; | ||
import { getHistoryEndDateFromNextBeginDate } from "../usagers/services"; | ||
|
||
export class UpdateEndDateHistoryMigration1704813169210 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
const total = await this.countHistoriesToMigrate(); | ||
|
||
console.log(total); | ||
|
||
for (let cpt = 0; cpt <= total; cpt = cpt + 2000) { | ||
console.log(`${cpt}/${total} migrated`); | ||
const usagerHistories: UsagerHistory[] = | ||
await usagerHistoryRepository.find({ | ||
where: { migrated: false }, | ||
order: { | ||
structureId: "DESC", | ||
usagerRef: "DESC", | ||
}, | ||
take: 2000, | ||
}); | ||
|
||
await queryRunner.startTransaction(); | ||
const uuidsToUpdate = []; | ||
for (const history of usagerHistories) { | ||
let needUdpate = false; | ||
|
||
const states: UsagerHistoryState[] = history.states; | ||
|
||
for (let i = 0; i < states.length - 1; i++) { | ||
const state = states[i]; | ||
|
||
const nextState = states[i + 1]; | ||
if (typeof nextState !== "undefined" && !state?.historyEndDate) { | ||
needUdpate = true; | ||
states[i].historyEndDate = getHistoryEndDateFromNextBeginDate( | ||
nextState.historyBeginDate | ||
); | ||
console.log({ | ||
structureId: history.structureId, | ||
usagerRef: history.usagerRef, | ||
historyBeginDate: state.historyBeginDate, | ||
historyEndDate: state.historyEndDate, | ||
NewHistoryEndDate: states[i].historyEndDate, | ||
}); | ||
console.log(); | ||
} | ||
} | ||
|
||
if (needUdpate) { | ||
await usagerHistoryRepository.update( | ||
{ uuid: history.uuid }, | ||
{ states: history.states } | ||
); | ||
} | ||
|
||
uuidsToUpdate.push(history.uuid); | ||
} | ||
|
||
await usagerHistoryRepository.update( | ||
{ uuid: In(uuidsToUpdate) }, | ||
{ migrated: true } | ||
); | ||
await queryRunner.commitTransaction(); | ||
} | ||
} | ||
|
||
public async down(_queryRunner: QueryRunner): Promise<void> { | ||
// | ||
} | ||
|
||
private countHistoriesToMigrate(): Promise<number> { | ||
return usagerHistoryRepository.countBy({ migrated: false }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters