mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-24 20:40:59 +00:00
Merge pull request #876 from hcengineering/fix-versioning
Fix model versioning
This commit is contained in:
commit
d898d7556e
@ -114,6 +114,7 @@ export async function restoreWorkspace (
|
||||
elasticUrl: string,
|
||||
transactorUrl: string
|
||||
): Promise<void> {
|
||||
console.log('Restoring workspace', mongoUrl, dbName, fileName)
|
||||
const client = new MongoClient(mongoUrl)
|
||||
try {
|
||||
await client.connect()
|
||||
@ -161,7 +162,7 @@ export async function restoreWorkspace (
|
||||
}
|
||||
}
|
||||
|
||||
await upgradeModel(dbName, transactorUrl)
|
||||
await upgradeModel(transactorUrl, dbName)
|
||||
|
||||
await rebuildElastic(mongoUrl, dbName, minio, elasticUrl)
|
||||
} finally {
|
||||
|
@ -36,8 +36,6 @@ import { createModel as templatesModel } from '@anticrm/model-templates'
|
||||
import { createModel as textEditorModel } from '@anticrm/model-text-editor'
|
||||
import { createModel as viewModel } from '@anticrm/model-view'
|
||||
import { createModel as workbenchModel } from '@anticrm/model-workbench'
|
||||
import { readFileSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
|
||||
const builder = new Builder()
|
||||
|
||||
@ -70,14 +68,11 @@ const builders = [
|
||||
for (const b of builders) {
|
||||
b(builder)
|
||||
}
|
||||
const packageFile = readFileSync(join(__dirname, '..', 'package.json')).toString()
|
||||
const json = JSON.parse(packageFile)
|
||||
const packageVersion = json.version.split('.')
|
||||
|
||||
export const version: Data<Version> = {
|
||||
major: parseInt(packageVersion[0]),
|
||||
minor: parseInt(packageVersion[1]),
|
||||
patch: parseInt(packageVersion[2])
|
||||
major: 0,
|
||||
minor: 6,
|
||||
patch: 0
|
||||
}
|
||||
|
||||
builder.createDoc(core.class.Version, core.space.Model, version, core.version.Model)
|
||||
|
@ -391,10 +391,10 @@ async function getWorkspaceAndAccount (
|
||||
export async function assignWorkspace (db: Db, email: string, workspace: string): Promise<void> {
|
||||
const { workspaceId, accountId } = await getWorkspaceAndAccount(db, email, workspace)
|
||||
// Add account into workspace.
|
||||
await db.collection(WORKSPACE_COLLECTION).updateOne({ _id: workspaceId }, { $push: { accounts: accountId } })
|
||||
await db.collection(WORKSPACE_COLLECTION).updateOne({ _id: workspaceId }, { $addToSet: { accounts: accountId } })
|
||||
|
||||
// Add workspace to account
|
||||
await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: accountId }, { $push: { workspaces: workspaceId } })
|
||||
await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: accountId }, { $addToSet: { workspaces: workspaceId } })
|
||||
|
||||
const account = await db.collection<Account>(ACCOUNT_COLLECTION).findOne({ _id: accountId })
|
||||
|
||||
@ -408,17 +408,33 @@ async function createEmployeeAccount (account: Account, workspace: string): Prom
|
||||
|
||||
const name = combineName(account.first, account.last)
|
||||
|
||||
const employee = await ops.createDoc(contact.class.Employee, contact.space.Employee, {
|
||||
name,
|
||||
city: '',
|
||||
channels: []
|
||||
})
|
||||
// Check if EmployeeAccoun is not exists
|
||||
const existingAccount = await ops.findOne(contact.class.EmployeeAccount, { email: account.email })
|
||||
|
||||
await ops.createDoc(contact.class.EmployeeAccount, core.space.Model, {
|
||||
email: account.email,
|
||||
employee,
|
||||
name
|
||||
})
|
||||
if (existingAccount === undefined) {
|
||||
const employee = await ops.createDoc(contact.class.Employee, contact.space.Employee, {
|
||||
name,
|
||||
city: '',
|
||||
channels: []
|
||||
})
|
||||
|
||||
await ops.createDoc(contact.class.EmployeeAccount, core.space.Model, {
|
||||
email: account.email,
|
||||
employee,
|
||||
name
|
||||
})
|
||||
} else {
|
||||
const employee = await ops.findOne(contact.class.Employee, { _id: existingAccount.employee })
|
||||
if (employee === undefined) {
|
||||
// Employee was deleted, let's restore it.
|
||||
const employeeId = await ops.createDoc(contact.class.Employee, contact.space.Employee, {
|
||||
name,
|
||||
city: '',
|
||||
channels: []
|
||||
})
|
||||
await ops.updateDoc(contact.class.EmployeeAccount, existingAccount.space, existingAccount._id, { employee: employeeId })
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await connection.close()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user