Upgrade workspace model (#402)

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-11-29 12:09:55 +01:00 committed by GitHub
parent 3f62998052
commit 6ae2337038
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -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 <name>')
.description('upgrade workspace')
.action(async (workspace, cmd) => {
await upgradeWorkspace(mongodbUri, workspace, transactorUrl, minio)
})
program
.command('drop-workspace <name>')
.description('drop workspace')

View File

@ -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<void> {
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()
}
}