Skip to content

Commit

Permalink
cli arg to skip work
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Fontanier committed Dec 16, 2024
1 parent 9bf5d47 commit 12372a3
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion front/migrations/20241211_parents_migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ async function migrateDocument({
dataSource,
coreDocument,
execute,
skipIfParentsAreAlreadyCorrect,
}: {
action: MigratorAction;
migrator: ProviderMigrator;
Expand All @@ -274,6 +275,7 @@ async function migrateDocument({
document_id: string;
};
execute: boolean;
skipIfParentsAreAlreadyCorrect: boolean;
}) {
let newParents = coreDocument.parents;
let newParentId: string | null = null;
Expand All @@ -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 () => {
Expand Down Expand Up @@ -417,11 +434,13 @@ async function migrateDataSource({
migrator,
dataSource,
execute,
skipIfParentsAreAlreadyCorrect,
}: {
action: MigratorAction;
migrator: ProviderMigrator;
dataSource: DataSourceModel;
execute: boolean;
skipIfParentsAreAlreadyCorrect: boolean;
}) {
const corePrimary = getCorePrimaryDbConnection();

Expand Down Expand Up @@ -480,6 +499,7 @@ async function migrateDataSource({
migrator,
dataSource,
coreDocument,
skipIfParentsAreAlreadyCorrect,
execute,
}),
{ concurrency: DOCUMENT_CONCURRENCY }
Expand Down Expand Up @@ -555,6 +575,7 @@ async function migrateAll({
migrator,
nextDataSourceId,
execute,
skipIfParentsAreAlreadyCorrect,
}: {
provider: ConnectorProvider;
action: MigratorAction;
Expand Down Expand Up @@ -584,6 +605,7 @@ async function migrateAll({
action,
dataSource,
execute,
skipIfParentsAreAlreadyCorrect,
});
} else {
logger.info({ dataSourceId: dataSource.id }, "SKIP");
Expand All @@ -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"`
Expand All @@ -630,6 +663,7 @@ makeScript(
migrator,
nextDataSourceId,
execute,
skipIfParentsAreAlreadyCorrect,
});
}
);

0 comments on commit 12372a3

Please sign in to comment.