From 12372a357abc8d31870c971e4414d0956d566c13 Mon Sep 17 00:00:00 2001 From: Henry Fontanier Date: Mon, 16 Dec 2024 14:23:19 +0100 Subject: [PATCH] cli arg to skip work --- front/migrations/20241211_parents_migrator.ts | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/front/migrations/20241211_parents_migrator.ts b/front/migrations/20241211_parents_migrator.ts index c6309af8d264..9125a6bd6193 100644 --- a/front/migrations/20241211_parents_migrator.ts +++ b/front/migrations/20241211_parents_migrator.ts @@ -264,6 +264,7 @@ async function migrateDocument({ dataSource, coreDocument, execute, + skipIfParentsAreAlreadyCorrect, }: { action: MigratorAction; migrator: ProviderMigrator; @@ -274,6 +275,7 @@ async function migrateDocument({ document_id: string; }; execute: boolean; + skipIfParentsAreAlreadyCorrect: boolean; }) { let newParents = coreDocument.parents; let newParentId: string | null = null; @@ -295,6 +297,21 @@ async function migrateDocument({ throw e; } + if ( + skipIfParentsAreAlreadyCorrect && + newParents.every((x, i) => x === coreDocument.parents[i]) + ) { + logger.info( + { + documentId: coreDocument.document_id, + fromParents: coreDocument.parents, + toParents: newParents, + }, + `SKIP document (parents are already correct)` + ); + return new Ok(undefined); + } + if (execute) { const updateRes = await withRetries( async () => { @@ -417,11 +434,13 @@ async function migrateDataSource({ migrator, dataSource, execute, + skipIfParentsAreAlreadyCorrect, }: { action: MigratorAction; migrator: ProviderMigrator; dataSource: DataSourceModel; execute: boolean; + skipIfParentsAreAlreadyCorrect: boolean; }) { const corePrimary = getCorePrimaryDbConnection(); @@ -480,6 +499,7 @@ async function migrateDataSource({ migrator, dataSource, coreDocument, + skipIfParentsAreAlreadyCorrect, execute, }), { concurrency: DOCUMENT_CONCURRENCY } @@ -555,6 +575,7 @@ async function migrateAll({ migrator, nextDataSourceId, execute, + skipIfParentsAreAlreadyCorrect, }: { provider: ConnectorProvider; action: MigratorAction; @@ -584,6 +605,7 @@ async function migrateAll({ action, dataSource, execute, + skipIfParentsAreAlreadyCorrect, }); } else { logger.info({ dataSourceId: dataSource.id }, "SKIP"); @@ -601,13 +623,24 @@ makeScript( type: "string", required: true, }, + skipIfParentsAreAlreadyCorrect: { + type: "boolean", + required: false, + default: false, + }, nextDataSourceId: { type: "number", required: false, default: 0, }, }, - async ({ provider, action, nextDataSourceId, execute }) => { + async ({ + provider, + action, + nextDataSourceId, + execute, + skipIfParentsAreAlreadyCorrect, + }) => { if (!isMigratorAction(action)) { console.error( `Invalid action ${action}, supported actions are "transform" and "clean"` @@ -630,6 +663,7 @@ makeScript( migrator, nextDataSourceId, execute, + skipIfParentsAreAlreadyCorrect, }); } );