diff --git a/dev/tool/src/index.ts b/dev/tool/src/index.ts index df309a081d..f6ac27846e 100644 --- a/dev/tool/src/index.ts +++ b/dev/tool/src/index.ts @@ -21,7 +21,7 @@ import { createContributingClient } from '@anticrm/contrib' import core, { TxOperations } from '@anticrm/core' import { encode } from 'jwt-simple' import { Client } from 'minio' -import { initWorkspace } from './workspace' +import { initWorkspace, upgradeWorkspace } from './workspace' import contact, { combineName } from '@anticrm/contact' @@ -148,6 +148,13 @@ program }) }) +program + .command('upgrade-workspace ') + .description('upgrade workspace') + .action(async (workspace, cmd) => { + await upgradeWorkspace(mongodbUri, workspace, transactorUrl, minio) + }) + program .command('drop-workspace ') .description('drop workspace') diff --git a/dev/tool/src/workspace.ts b/dev/tool/src/workspace.ts index dc3e54f38a..542617671a 100644 --- a/dev/tool/src/workspace.ts +++ b/dev/tool/src/workspace.ts @@ -19,6 +19,7 @@ import core, { DOMAIN_TX, Tx } from '@anticrm/core' import { createContributingClient } from '@anticrm/contrib' import { encode } from 'jwt-simple' import { Client } from 'minio' +import contact from '@anticrm/contact' import * as txJson from './model.tx.json' @@ -57,3 +58,30 @@ export async function initWorkspace (mongoUrl: string, dbName: string, clientUrl await client.close() } } + +/** + * @public + */ +export async function upgradeWorkspace (mongoUrl: string, dbName: string, clientUrl: string, minio: Client): Promise { + const client = new MongoClient(mongoUrl) + try { + await client.connect() + const db = client.db(dbName) + + console.log('removing model...') + // we're preserving accounts (created by core.account.System). + const result = await db.collection(DOMAIN_TX).deleteMany({ + objectSpace: core.space.Model, + modifiedBy: core.account.System, + _class: { $ne: contact.class.EmployeeAccount } + }) + console.log(`${result.deletedCount} transactions deleted.`) + + console.log('creating model...') + const model = txes.filter(tx => tx.objectSpace === core.space.Model) + const insert = await db.collection(DOMAIN_TX).insertMany(model as Document[]) + console.log(`${insert.insertedCount} model transactions inserted.`) + } finally { + await client.close() + } +}