From 50408d307df6794e98084cce18a1cb2a4195e6a4 Mon Sep 17 00:00:00 2001 From: Romaric Mourgues Date: Tue, 28 Mar 2023 10:12:02 +0200 Subject: [PATCH 1/3] Add options to drive mirgation script --- .../node/src/cli/cmds/migration_cmds/drive.ts | 21 +++++++++++++++---- .../php-drive-file/drive-migrator-service.ts | 21 ++++++++++++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts b/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts index eb17607c7..3fa85f413 100644 --- a/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts +++ b/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts @@ -24,13 +24,26 @@ const services = [ const command: yargs.CommandModule = { command: "drive", describe: "migrate php drive items to node", - builder: {}, - handler: async _argv => { - console.log("test"); + builder: { + from: { + default: null, + type: "string", + description: "Start migration from this company ID", + }, + onlyCompany: { + default: null, + type: "string", + description: "Migrate only this company ID", + }, + }, + handler: async argv => { + const from = argv.from as string | null; + const onlyCompany = argv.onlyCompany as string | null; + const spinner = ora({ text: "Migrating php drive - " }).start(); const platform = await twake.run(services); await globalResolver.doInit(platform); - const migrator = new DriveMigrator(platform); + const migrator = new DriveMigrator(platform, {from, onlyCompany}}); await migrator.run(); diff --git a/twake/backend/node/src/cli/cmds/migration_cmds/php-drive-file/drive-migrator-service.ts b/twake/backend/node/src/cli/cmds/migration_cmds/php-drive-file/drive-migrator-service.ts index 8d0c19f07..65a794747 100644 --- a/twake/backend/node/src/cli/cmds/migration_cmds/php-drive-file/drive-migrator-service.ts +++ b/twake/backend/node/src/cli/cmds/migration_cmds/php-drive-file/drive-migrator-service.ts @@ -30,8 +30,19 @@ interface WorkspaceExecutionContext extends CompanyExecutionContext { class DriveMigrator { private phpDriveService: PhpDriveFileService; private nodeRepository: Repository; + private options: { + fromCompany?: string; + onlyCompany?: string; + }; - constructor(readonly _platform: TwakePlatform) { + constructor( + readonly _platform: TwakePlatform, + options?: { + fromCompany?: string; + onlyCompany?: string; + }, + ) { + this.options = options; this.phpDriveService = new PhpDriveFileService(); } @@ -59,7 +70,15 @@ class DriveMigrator { const companyListResult = await globalResolver.services.companies.getCompanies(page); page = companyListResult.nextPage as Pagination; + let didPassFromCompany = false; + for (const company of companyListResult.getEntities()) { + if (this.options.onlyCompany && this.options.onlyCompany !== company.id) continue; + if (this.options.fromCompany && this.options.fromCompany === company.id) { + didPassFromCompany = true; + } + if (this.options.fromCompany && !didPassFromCompany) continue; + await this.migrateCompany(company, { ...context, company: { id: company.id }, From f7222b4d09cfae0db61d0a5ac156a95ccb1d8df2 Mon Sep 17 00:00:00 2001 From: Romaric Mourgues Date: Tue, 28 Mar 2023 10:22:03 +0200 Subject: [PATCH 2/3] Fix tests --- twake/backend/node/src/cli/cmds/migration_cmds/drive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts b/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts index 3fa85f413..3bd6ea313 100644 --- a/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts +++ b/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts @@ -43,7 +43,7 @@ const command: yargs.CommandModule = { const spinner = ora({ text: "Migrating php drive - " }).start(); const platform = await twake.run(services); await globalResolver.doInit(platform); - const migrator = new DriveMigrator(platform, {from, onlyCompany}}); + const migrator = new DriveMigrator(platform, {fromCompany: from, onlyCompany}}); await migrator.run(); From e04ab11736bcdd647a99a17a3efab379b651984d Mon Sep 17 00:00:00 2001 From: Romaric Mourgues Date: Tue, 28 Mar 2023 10:46:28 +0200 Subject: [PATCH 3/3] Fix code --- twake/backend/node/src/cli/cmds/migration_cmds/drive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts b/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts index 3bd6ea313..89ae6a654 100644 --- a/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts +++ b/twake/backend/node/src/cli/cmds/migration_cmds/drive.ts @@ -43,7 +43,7 @@ const command: yargs.CommandModule = { const spinner = ora({ text: "Migrating php drive - " }).start(); const platform = await twake.run(services); await globalResolver.doInit(platform); - const migrator = new DriveMigrator(platform, {fromCompany: from, onlyCompany}}); + const migrator = new DriveMigrator(platform, { fromCompany: from, onlyCompany }); await migrator.run();