mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-14 04:08:19 +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,
|
pgClient: postgres.Sql,
|
||||||
ws: Workspace,
|
ws: Workspace,
|
||||||
region: string,
|
region: string,
|
||||||
include?: Set<string>
|
include?: Set<string>,
|
||||||
|
force = false
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const wsId = getWorkspaceId(ws.workspace)
|
const wsId = getWorkspaceId(ws.workspace)
|
||||||
@ -102,12 +103,24 @@ async function moveWorkspace (
|
|||||||
insertFields.push(field)
|
insertFields.push(field)
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
|
const toRemove: string[] = []
|
||||||
while (docs.length < 50000) {
|
while (docs.length < 50000) {
|
||||||
const doc = (await cursor.next()) as Doc | null
|
const doc = (await cursor.next()) as Doc | null
|
||||||
if (doc === null) break
|
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)
|
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
|
if (docs.length === 0) break
|
||||||
while (docs.length > 0) {
|
while (docs.length > 0) {
|
||||||
const part = docs.splice(0, 500)
|
const part = docs.splice(0, 500)
|
||||||
@ -138,7 +151,8 @@ export async function moveWorkspaceFromMongoToPG (
|
|||||||
dbUrl: string | undefined,
|
dbUrl: string | undefined,
|
||||||
ws: Workspace,
|
ws: Workspace,
|
||||||
region: string,
|
region: string,
|
||||||
include?: Set<string>
|
include?: Set<string>,
|
||||||
|
force?: boolean
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (dbUrl === undefined) {
|
if (dbUrl === undefined) {
|
||||||
throw new Error('dbUrl is required')
|
throw new Error('dbUrl is required')
|
||||||
@ -148,7 +162,7 @@ export async function moveWorkspaceFromMongoToPG (
|
|||||||
const pg = getDBClient(dbUrl)
|
const pg = getDBClient(dbUrl)
|
||||||
const pgClient = await pg.getClient()
|
const pgClient = await pg.getClient()
|
||||||
|
|
||||||
await moveWorkspace(accountDb, mongo, pgClient, ws, region, include)
|
await moveWorkspace(accountDb, mongo, pgClient, ws, region, include, force)
|
||||||
pg.close()
|
pg.close()
|
||||||
client.close()
|
client.close()
|
||||||
}
|
}
|
||||||
|
@ -1669,12 +1669,14 @@ export function devTool (
|
|||||||
program
|
program
|
||||||
.command('move-workspace-to-pg <workspace> <region>')
|
.command('move-workspace-to-pg <workspace> <region>')
|
||||||
.option('-i, --include <include>', 'A list of ; separated domain names to include during backup', '*')
|
.option('-i, --include <include>', 'A list of ; separated domain names to include during backup', '*')
|
||||||
|
.option('-f|--force [force]', 'Force update', false)
|
||||||
.action(
|
.action(
|
||||||
async (
|
async (
|
||||||
workspace: string,
|
workspace: string,
|
||||||
region: string,
|
region: string,
|
||||||
cmd: {
|
cmd: {
|
||||||
include: string
|
include: string
|
||||||
|
force: boolean
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const { dbUrl } = prepareTools()
|
const { dbUrl } = prepareTools()
|
||||||
@ -1694,7 +1696,8 @@ export function devTool (
|
|||||||
dbUrl,
|
dbUrl,
|
||||||
workspaceInfo,
|
workspaceInfo,
|
||||||
region,
|
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