tool for reindexing elasticsearch db (#5643)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
Vyacheslav Tumanov 2024-05-23 22:16:57 +05:00 committed by GitHub
parent 8b0d099b1a
commit ce6ce23444
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 2 deletions

View File

@ -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')

View File

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