-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into TM-1752-Dashboard-Mission-Locales
- Loading branch information
Showing
9 changed files
with
278 additions
and
91 deletions.
There are no files selected for viewing
8 changes: 2 additions & 6 deletions
8
.infra/files/configs/reverse_proxy/locations/80_metabase.conf.template
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 |
---|---|---|
@@ -1,8 +1,4 @@ | ||
location ~ ^/metabase(?:/(.*))?$ { | ||
location ~ ^/metabase(/?)(.*)?$ { | ||
set $upstream http://metabase:3000; | ||
proxy_pass $upstream/$1$is_args$args; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-Host $server_name; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
include includes/proxy_sub_path.conf; | ||
} |
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
133 changes: 133 additions & 0 deletions
133
server/src/db/migrations/20241211154816-deduplication-effectifs-auto.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,133 @@ | ||
import { addJob } from "job-processor"; | ||
import type { ObjectId } from "mongodb"; | ||
import { MOTIF_SUPPRESSION } from "shared/constants"; | ||
|
||
import { softDeleteEffectif } from "@/common/actions/effectifs.actions"; | ||
import { effectifsDb, effectifsDECADb } from "@/common/model/collections"; | ||
import { recreateIndexes } from "@/jobs/db/recreateIndexes"; | ||
|
||
export const up = async () => { | ||
const effectifDuplicats = await effectifsDb() | ||
.aggregate<{ | ||
_id: { | ||
annee_scolaire: string; | ||
cfd: string; | ||
rncp: string; | ||
id_erp_apprenant: string; | ||
organisme_id: string; | ||
}; | ||
count: number; | ||
docs: { | ||
id: ObjectId; | ||
updated_at: Date; | ||
}[]; | ||
}>([ | ||
{ | ||
$group: { | ||
_id: { | ||
annee_scolaire: "$annee_scolaire", | ||
cfd: "$formation.cfd", | ||
rncp: "$formation.rncp", | ||
id_erp_apprenant: "$id_erp_apprenant", | ||
organisme_id: "$organisme_id", | ||
}, | ||
count: { | ||
$sum: 1, | ||
}, | ||
docs: { | ||
$addToSet: { | ||
id: "$_id", | ||
updated_at: "$updated_at", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
$match: { count: { $gt: 1 } }, | ||
}, | ||
]) | ||
.toArray(); | ||
|
||
for (const effectifDuplicat of effectifDuplicats) { | ||
const { docs } = effectifDuplicat; | ||
const lastUpdatedDoc = docs.reduce((acc, doc) => { | ||
if (doc.updated_at.getTime() > acc.updated_at.getTime()) { | ||
return doc; | ||
} | ||
|
||
return acc; | ||
}, docs[0]); | ||
|
||
await softDeleteEffectif(lastUpdatedDoc.id, null, { | ||
motif: MOTIF_SUPPRESSION.Doublon, | ||
description: "Suppression du doublon suite à la migration index unique sur effectifs", | ||
}); | ||
} | ||
|
||
const effectifDecaDuplicats = await effectifsDECADb() | ||
.aggregate<{ | ||
_id: { | ||
annee_scolaire: string; | ||
cfd: string; | ||
rncp: string; | ||
id_erp_apprenant: string; | ||
organisme_id: string; | ||
}; | ||
count: number; | ||
docs: { | ||
id: ObjectId; | ||
updated_at: Date; | ||
}[]; | ||
}>([ | ||
{ | ||
$group: { | ||
_id: { | ||
annee_scolaire: "$annee_scolaire", | ||
cfd: "$formation.cfd", | ||
rncp: "$formation.rncp", | ||
id_erp_apprenant: "$id_erp_apprenant", | ||
organisme_id: "$organisme_id", | ||
}, | ||
count: { | ||
$sum: 1, | ||
}, | ||
docs: { | ||
$addToSet: { | ||
id: "$_id", | ||
updated_at: "$updated_at", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
$match: { count: { $gt: 1 } }, | ||
}, | ||
]) | ||
.toArray(); | ||
|
||
for (const effectifDuplicat of effectifDecaDuplicats) { | ||
const { docs } = effectifDuplicat; | ||
const lastUpdatedDoc = docs.reduce((acc, doc) => { | ||
if (doc.updated_at.getTime() > acc.updated_at.getTime()) { | ||
return doc; | ||
} | ||
|
||
return acc; | ||
}, docs[0]); | ||
|
||
await effectifsDECADb().deleteMany({ _id: { $ne: lastUpdatedDoc.id } }); | ||
} | ||
|
||
// Recreate indexes before dropping unique index as it will be used to create new indexes | ||
await recreateIndexes({ drop: false }); | ||
|
||
// DROP unique index | ||
await effectifsDb().dropIndex( | ||
"organisme_id_1_annee_scolaire_1_id_erp_apprenant_1_apprenant.nom_1_apprenant.prenom_1_formation.cfd_1_formation.annee_1" | ||
); | ||
|
||
await addJob({ | ||
name: "tmp:migration:duplicat-formation", | ||
queued: true, | ||
}); | ||
}; |
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
Oops, something went wrong.