Skip to content

Commit

Permalink
馃搧 Add options to drive mirgation script (#2787)
Browse files Browse the repository at this point in the history
* Add options to drive mirgation script

* Fix tests

* Fix code
  • Loading branch information
RomaricMourgues committed Mar 28, 2023
1 parent 98195c3 commit f375d46
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
21 changes: 17 additions & 4 deletions twake/backend/node/src/cli/cmds/migration_cmds/drive.ts
Expand Up @@ -24,13 +24,26 @@ const services = [
const command: yargs.CommandModule<unknown, unknown> = {
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, { fromCompany: from, onlyCompany });

await migrator.run();

Expand Down
Expand Up @@ -30,8 +30,19 @@ interface WorkspaceExecutionContext extends CompanyExecutionContext {
class DriveMigrator {
private phpDriveService: PhpDriveFileService;
private nodeRepository: Repository<DriveFile>;
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();
}

Expand Down Expand Up @@ -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 },
Expand Down

0 comments on commit f375d46

Please sign in to comment.