mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-28 04:25:03 +02:00
Fix markdown migration tool (#6407)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
@@ -1300,19 +1300,19 @@ export function devTool (
|
||||
await withDatabase(mongodbUri, async (db, client) => {
|
||||
await withStorage(mongodbUri, async (adapter) => {
|
||||
const workspaces = await listWorkspacesPure(db)
|
||||
let index = 0
|
||||
for (const workspace of workspaces) {
|
||||
if (cmd.workspace !== '' && workspace.workspace !== cmd.workspace) {
|
||||
continue
|
||||
}
|
||||
|
||||
const wsId = getWorkspaceId(workspace.workspace)
|
||||
const endpoint = await getTransactorEndpoint(generateToken(systemAccountEmail, wsId), 'external')
|
||||
console.log('processing workspace', workspace.workspace, index, workspaces.length)
|
||||
|
||||
console.log('processing workspace', workspace.workspace)
|
||||
|
||||
await migrateMarkup(toolCtx, adapter, wsId, client, endpoint, parseInt(cmd.concurrency))
|
||||
await migrateMarkup(toolCtx, adapter, wsId, client, mongodbUri, parseInt(cmd.concurrency))
|
||||
|
||||
console.log('...done', workspace.workspace)
|
||||
index++
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
+22
-30
@@ -15,7 +15,7 @@ import core, {
|
||||
} from '@hcengineering/core'
|
||||
import { getMongoClient, getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { type StorageAdapter } from '@hcengineering/server-core'
|
||||
import { connect } from '@hcengineering/server-tool'
|
||||
import { connect, fetchModelFromMongo } from '@hcengineering/server-tool'
|
||||
import { jsonToText, markupToYDoc } from '@hcengineering/text'
|
||||
import { type Db, type FindCursor, type MongoClient } from 'mongodb'
|
||||
|
||||
@@ -120,47 +120,39 @@ export async function migrateMarkup (
|
||||
storageAdapter: StorageAdapter,
|
||||
workspaceId: WorkspaceId,
|
||||
client: MongoClient,
|
||||
transactorUrl: string,
|
||||
mongodbUri: string,
|
||||
concurrency: number
|
||||
): Promise<void> {
|
||||
const connection = (await connect(transactorUrl, workspaceId, undefined, {
|
||||
mode: 'backup'
|
||||
})) as unknown as CoreClient
|
||||
|
||||
const hierarchy = connection.getHierarchy()
|
||||
const { hierarchy } = await fetchModelFromMongo(ctx, mongodbUri, workspaceId)
|
||||
|
||||
const workspaceDb = client.db(workspaceId.name)
|
||||
|
||||
try {
|
||||
const classes = hierarchy.getDescendants(core.class.Doc)
|
||||
for (const _class of classes) {
|
||||
const domain = hierarchy.findDomain(_class)
|
||||
if (domain === undefined) continue
|
||||
const classes = hierarchy.getDescendants(core.class.Doc)
|
||||
for (const _class of classes) {
|
||||
const domain = hierarchy.findDomain(_class)
|
||||
if (domain === undefined) continue
|
||||
|
||||
const allAttributes = hierarchy.getAllAttributes(_class)
|
||||
const attributes = Array.from(allAttributes.values()).filter((attribute) => {
|
||||
return hierarchy.isDerived(attribute.type._class, 'core:class:TypeCollaborativeMarkup' as Ref<Class<Doc>>)
|
||||
})
|
||||
const allAttributes = hierarchy.getAllAttributes(_class)
|
||||
const attributes = Array.from(allAttributes.values()).filter((attribute) => {
|
||||
return hierarchy.isDerived(attribute.type._class, 'core:class:TypeCollaborativeMarkup' as Ref<Class<Doc>>)
|
||||
})
|
||||
|
||||
if (attributes.length === 0) continue
|
||||
if (hierarchy.isMixin(_class) && attributes.every((p) => p.attributeOf !== _class)) continue
|
||||
if (attributes.length === 0) continue
|
||||
if (hierarchy.isMixin(_class) && attributes.every((p) => p.attributeOf !== _class)) continue
|
||||
|
||||
const collection = workspaceDb.collection(domain)
|
||||
const collection = workspaceDb.collection(domain)
|
||||
|
||||
const filter = hierarchy.isMixin(_class) ? { [_class]: { $exists: true } } : { _class }
|
||||
const filter = hierarchy.isMixin(_class) ? { [_class]: { $exists: true } } : { _class }
|
||||
|
||||
const count = await collection.countDocuments(filter)
|
||||
const iterator = collection.find<Doc>(filter)
|
||||
const count = await collection.countDocuments(filter)
|
||||
const iterator = collection.find<Doc>(filter)
|
||||
|
||||
try {
|
||||
console.log('processing', _class, '->', count)
|
||||
await processMigrateMarkupFor(ctx, hierarchy, storageAdapter, workspaceId, attributes, iterator, concurrency)
|
||||
} finally {
|
||||
await iterator.close()
|
||||
}
|
||||
try {
|
||||
console.log('processing', _class, '->', count)
|
||||
await processMigrateMarkupFor(ctx, hierarchy, storageAdapter, workspaceId, attributes, iterator, concurrency)
|
||||
} finally {
|
||||
await iterator.close()
|
||||
}
|
||||
} finally {
|
||||
await connection.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user