fix: ajouter try/catch dans les blocs else de migrateExistingItems pour gérer les violations UNIQUE
This commit is contained in:
@@ -546,6 +546,7 @@ export async function migrateExistingItems(): Promise<MigrationSummary> {
|
||||
const newDedupKey = dedupHash(normalizedTitle + "|veille");
|
||||
|
||||
// Mettre à jour le principal
|
||||
try {
|
||||
await db.update(veilleItems)
|
||||
.set({
|
||||
categorie: newCategorie,
|
||||
@@ -563,6 +564,17 @@ export async function migrateExistingItems(): Promise<MigrationSummary> {
|
||||
veilleMerged++;
|
||||
}
|
||||
veilleUpdated++;
|
||||
} catch (e: any) {
|
||||
// Si le newDedupKey existe déjà → supprimer tout le groupe
|
||||
if (e?.code === "ER_DUP_ENTRY" || e?.cause?.code === "ER_DUP_ENTRY" || e?.cause?.message?.includes("Duplicate entry")) {
|
||||
for (const row of sorted) {
|
||||
await db.delete(veilleItems).where(eq(veilleItems.id, row.id));
|
||||
veilleMerged++;
|
||||
}
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,6 +634,7 @@ export async function migrateExistingItems(): Promise<MigrationSummary> {
|
||||
const normalizedTitle = buildMergeKey(primary.titre || "");
|
||||
const newDedupKey = dedupHash(normalizedTitle + "|aap");
|
||||
|
||||
try {
|
||||
await db.update(aapItems)
|
||||
.set({
|
||||
region: "Auvergne-Rhône-Alpes",
|
||||
@@ -637,6 +650,17 @@ export async function migrateExistingItems(): Promise<MigrationSummary> {
|
||||
aapMerged++;
|
||||
}
|
||||
aapUpdated++;
|
||||
} catch (e: any) {
|
||||
// Si le newDedupKey existe déjà → supprimer tout le groupe
|
||||
if (e?.code === "ER_DUP_ENTRY" || e?.cause?.code === "ER_DUP_ENTRY" || e?.cause?.message?.includes("Duplicate entry")) {
|
||||
for (const row of sorted) {
|
||||
await db.delete(aapItems).where(eq(aapItems.id, row.id));
|
||||
aapMerged++;
|
||||
}
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user