mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 03:40:48 +00:00
Force move tool (#7095)
This commit is contained in:
parent
753661a7e8
commit
0647206938
@ -68,7 +68,8 @@ async function moveWorkspace (
|
||||
pgClient: postgres.Sql,
|
||||
ws: Workspace,
|
||||
region: string,
|
||||
include?: Set<string>
|
||||
include?: Set<string>,
|
||||
force = false
|
||||
): Promise<void> {
|
||||
try {
|
||||
const wsId = getWorkspaceId(ws.workspace)
|
||||
@ -102,12 +103,24 @@ async function moveWorkspace (
|
||||
insertFields.push(field)
|
||||
}
|
||||
while (true) {
|
||||
const toRemove: string[] = []
|
||||
while (docs.length < 50000) {
|
||||
const doc = (await cursor.next()) as Doc | null
|
||||
if (doc === null) break
|
||||
if (currentIds.has(doc._id)) continue
|
||||
if (currentIds.has(doc._id)) {
|
||||
if (force) {
|
||||
toRemove.push(doc._id)
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
docs.push(doc)
|
||||
}
|
||||
if (toRemove.length > 0) {
|
||||
await retryTxn(pgClient, async (client) => {
|
||||
await client`DELETE FROM ${client(translateDomain(domain))} WHERE "workspaceId" = ${ws.workspace} AND _id IN (${client(toRemove)})`
|
||||
})
|
||||
}
|
||||
if (docs.length === 0) break
|
||||
while (docs.length > 0) {
|
||||
const part = docs.splice(0, 500)
|
||||
@ -138,7 +151,8 @@ export async function moveWorkspaceFromMongoToPG (
|
||||
dbUrl: string | undefined,
|
||||
ws: Workspace,
|
||||
region: string,
|
||||
include?: Set<string>
|
||||
include?: Set<string>,
|
||||
force?: boolean
|
||||
): Promise<void> {
|
||||
if (dbUrl === undefined) {
|
||||
throw new Error('dbUrl is required')
|
||||
@ -148,7 +162,7 @@ export async function moveWorkspaceFromMongoToPG (
|
||||
const pg = getDBClient(dbUrl)
|
||||
const pgClient = await pg.getClient()
|
||||
|
||||
await moveWorkspace(accountDb, mongo, pgClient, ws, region, include)
|
||||
await moveWorkspace(accountDb, mongo, pgClient, ws, region, include, force)
|
||||
pg.close()
|
||||
client.close()
|
||||
}
|
||||
|
@ -1669,12 +1669,14 @@ export function devTool (
|
||||
program
|
||||
.command('move-workspace-to-pg <workspace> <region>')
|
||||
.option('-i, --include <include>', 'A list of ; separated domain names to include during backup', '*')
|
||||
.option('-f|--force [force]', 'Force update', false)
|
||||
.action(
|
||||
async (
|
||||
workspace: string,
|
||||
region: string,
|
||||
cmd: {
|
||||
include: string
|
||||
force: boolean
|
||||
}
|
||||
) => {
|
||||
const { dbUrl } = prepareTools()
|
||||
@ -1694,7 +1696,8 @@ export function devTool (
|
||||
dbUrl,
|
||||
workspaceInfo,
|
||||
region,
|
||||
cmd.include === '*' ? undefined : new Set(cmd.include.split(';').map((it) => it.trim()))
|
||||
cmd.include === '*' ? undefined : new Set(cmd.include.split(';').map((it) => it.trim())),
|
||||
cmd.force
|
||||
)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user