mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 21:50:34 +03:00
tool for reindexing elasticsearch db (#5643)
Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
parent
8b0d099b1a
commit
ce6ce23444
@ -51,7 +51,7 @@ import { buildStorageFromConfig, storageConfigFromEnv } from '@hcengineering/ser
|
||||
import { program, type Command } from 'commander'
|
||||
import { type Db, type MongoClient } from 'mongodb'
|
||||
import { clearTelegramHistory } from './telegram'
|
||||
import { diffWorkspace, updateField } from './workspace'
|
||||
import { diffWorkspace, recreateElastic, updateField } from './workspace'
|
||||
|
||||
import core, {
|
||||
AccountRole,
|
||||
@ -989,6 +989,14 @@ export function devTool (
|
||||
}
|
||||
)
|
||||
|
||||
program
|
||||
.command('recreate-elastic-indexes <workspace>')
|
||||
.description('reindex workspace to elastic')
|
||||
.action(async (workspace: string) => {
|
||||
const { mongodbUri } = prepareTools()
|
||||
await recreateElastic(mongodbUri, getWorkspaceId(workspace, productId), transactorUrl)
|
||||
})
|
||||
|
||||
program
|
||||
.command('fix-json-markup <workspace>')
|
||||
.description('fixes double converted json markup')
|
||||
|
@ -22,7 +22,8 @@ import core, {
|
||||
type Tx,
|
||||
type WorkspaceId,
|
||||
type Ref,
|
||||
type Doc
|
||||
type Doc,
|
||||
DOMAIN_DOC_INDEX_STATE
|
||||
} from '@hcengineering/core'
|
||||
import { getWorkspaceDB } from '@hcengineering/mongo'
|
||||
import { MongoClient } from 'mongodb'
|
||||
@ -97,3 +98,25 @@ export async function updateField (
|
||||
await connection.close()
|
||||
}
|
||||
}
|
||||
|
||||
export async function recreateElastic (
|
||||
mongoUrl: string,
|
||||
workspaceId: WorkspaceId,
|
||||
transactorUrl: string
|
||||
): Promise<void> {
|
||||
const client = new MongoClient(mongoUrl)
|
||||
const connection = (await connect(transactorUrl, workspaceId, undefined, {
|
||||
mode: 'backup'
|
||||
})) as unknown as CoreClient & BackupClient
|
||||
try {
|
||||
await client.connect()
|
||||
const db = getWorkspaceDB(client, workspaceId)
|
||||
await db
|
||||
.collection(DOMAIN_DOC_INDEX_STATE)
|
||||
.updateMany({ _class: core.class.DocIndexState }, { $set: { stages: {} } })
|
||||
await connection.sendForceClose()
|
||||
} finally {
|
||||
await client.close()
|
||||
await connection.close()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user