mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-02 13:52:40 +00:00
Upgrade workspace model (#402)
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
3f62998052
commit
6ae2337038
@ -21,7 +21,7 @@ import { createContributingClient } from '@anticrm/contrib'
|
|||||||
import core, { TxOperations } from '@anticrm/core'
|
import core, { TxOperations } from '@anticrm/core'
|
||||||
import { encode } from 'jwt-simple'
|
import { encode } from 'jwt-simple'
|
||||||
import { Client } from 'minio'
|
import { Client } from 'minio'
|
||||||
import { initWorkspace } from './workspace'
|
import { initWorkspace, upgradeWorkspace } from './workspace'
|
||||||
|
|
||||||
import contact, { combineName } from '@anticrm/contact'
|
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
|
program
|
||||||
.command('drop-workspace <name>')
|
.command('drop-workspace <name>')
|
||||||
.description('drop workspace')
|
.description('drop workspace')
|
||||||
|
@ -19,6 +19,7 @@ import core, { DOMAIN_TX, Tx } from '@anticrm/core'
|
|||||||
import { createContributingClient } from '@anticrm/contrib'
|
import { createContributingClient } from '@anticrm/contrib'
|
||||||
import { encode } from 'jwt-simple'
|
import { encode } from 'jwt-simple'
|
||||||
import { Client } from 'minio'
|
import { Client } from 'minio'
|
||||||
|
import contact from '@anticrm/contact'
|
||||||
|
|
||||||
import * as txJson from './model.tx.json'
|
import * as txJson from './model.tx.json'
|
||||||
|
|
||||||
@ -57,3 +58,30 @@ export async function initWorkspace (mongoUrl: string, dbName: string, clientUrl
|
|||||||
await client.close()
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user