Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃搧 Add options to drive mirgation script #2787

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 17 additions & 4 deletions twake/backend/node/src/cli/cmds/migration_cmds/drive.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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