mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-11 21:11:57 +00:00
qfix: move tx tool improvements
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
6054724080
commit
3c380b9037
@ -386,8 +386,7 @@ export async function applyMissingTxMongoToPG (
|
||||
const wsid = getWorkspaceId(ws.workspace)
|
||||
const pgTransactorUrl = await getTransactorEndpoint(generateToken(systemAccountEmail, wsid), 'external')
|
||||
const connectionPg = (await connect(pgTransactorUrl, wsid, undefined, {
|
||||
mode: 'backup',
|
||||
model: 'upgrade'
|
||||
mode: 'backup'
|
||||
})) as unknown as CoreClient & BackupClient
|
||||
|
||||
try {
|
||||
@ -405,6 +404,7 @@ export async function applyMissingTxMongoToPG (
|
||||
const txes: Tx[] = []
|
||||
const iterator = mongoDb.collection(DOMAIN_TX).find({}, { sort: { modifiedOn: 'descending' } })
|
||||
let restored = false
|
||||
let errors = 0
|
||||
while (true) {
|
||||
const doc = await iterator.next()
|
||||
if (doc == null) {
|
||||
@ -416,13 +416,19 @@ export async function applyMissingTxMongoToPG (
|
||||
if (pgTx == null) {
|
||||
txes.push(doc as unknown as Tx)
|
||||
} else {
|
||||
for (const tx of txes) {
|
||||
// Applying in reverse order (so in ascending)
|
||||
for (const tx of txes.reverse()) {
|
||||
if (verbose) {
|
||||
ctx.info('Restoring tx', tx)
|
||||
}
|
||||
|
||||
if (!dryRun) {
|
||||
// TODO: actually restore
|
||||
try {
|
||||
await ops.tx(tx)
|
||||
} catch (err: any) {
|
||||
errors++
|
||||
ctx.error('Failed to restore tx', { tx, err })
|
||||
}
|
||||
}
|
||||
}
|
||||
restored = true
|
||||
@ -437,7 +443,11 @@ export async function applyMissingTxMongoToPG (
|
||||
|
||||
if (txes.length > 0) {
|
||||
if (restored) {
|
||||
ctx.info('Restored missing transactions for workspace', { workspace: ws.workspace, count: txes.length })
|
||||
ctx.info('Restored missing transactions for workspace', {
|
||||
workspace: ws.workspace,
|
||||
count: txes.length,
|
||||
errors
|
||||
})
|
||||
} else {
|
||||
ctx.error('Failed to restore missing transactions for workspace', {
|
||||
workspace: ws.workspace,
|
||||
|
@ -2359,20 +2359,21 @@ export function devTool (
|
||||
|
||||
program
|
||||
.command('apply-missing-tx-mongo-to-pg')
|
||||
.option('-w, --workspace <workspace>', 'A selected "workspace" only', '')
|
||||
.option('-w, --workspace <workspace>', 'Selected "workspaces" only, comma separated', '')
|
||||
.option('-d, --dryrun', 'Dry run', false)
|
||||
.option('-v, --verbose', 'Verbose', false)
|
||||
.option('-f, --force', 'Force', false)
|
||||
.description('applies missing transactions from mongo to pg')
|
||||
.action(async (cmd: { workspace?: string, dryrun: boolean, verbose: boolean, force: boolean }) => {
|
||||
.action(async (cmd: { workspace: string, dryrun: boolean, verbose: boolean, force: boolean }) => {
|
||||
let workspaces: Workspace[] = []
|
||||
const targetWorkspaces = cmd.workspace.split(',')
|
||||
|
||||
await withAccountDatabase(async (db) => {
|
||||
workspaces = await listWorkspacesPure(db)
|
||||
workspaces = workspaces
|
||||
.filter((p) => isActiveMode(p.mode))
|
||||
.filter((p) => p.region === 'europe' && p.targetRegion === 'europe' && p.message === 'restore-done done')
|
||||
.filter((p) => cmd.workspace === '' || p.workspace === cmd.workspace)
|
||||
.filter((p) => cmd.workspace === '' || targetWorkspaces.includes(p.workspace))
|
||||
.sort((a, b) => b.lastVisit - a.lastVisit)
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user