mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-22 19:11:33 +03:00
parent
dfb8507d32
commit
1ce18226ab
@ -72,6 +72,7 @@ async function moveWorkspace (
|
|||||||
force = false
|
force = false
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
console.log('move workspace', ws.workspaceName ?? ws.workspace)
|
||||||
const wsId = getWorkspaceId(ws.workspace)
|
const wsId = getWorkspaceId(ws.workspace)
|
||||||
const mongoDB = getWorkspaceMongoDB(mongo, wsId)
|
const mongoDB = getWorkspaceMongoDB(mongo, wsId)
|
||||||
const collections = await mongoDB.collections()
|
const collections = await mongoDB.collections()
|
||||||
@ -104,7 +105,7 @@ async function moveWorkspace (
|
|||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
const toRemove: string[] = []
|
const toRemove: string[] = []
|
||||||
while (docs.length < 50000) {
|
while (docs.length < 5000) {
|
||||||
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)) {
|
if (currentIds.has(doc._id)) {
|
||||||
@ -116,25 +117,30 @@ async function moveWorkspace (
|
|||||||
}
|
}
|
||||||
docs.push(doc)
|
docs.push(doc)
|
||||||
}
|
}
|
||||||
if (toRemove.length > 0) {
|
while (toRemove.length > 0) {
|
||||||
|
const part = toRemove.splice(0, 100)
|
||||||
await retryTxn(pgClient, async (client) => {
|
await retryTxn(pgClient, async (client) => {
|
||||||
await client.unsafe(
|
await client.unsafe(
|
||||||
`DELETE FROM ${translateDomain(domain)} WHERE "workspaceId" = '${ws.workspace}' AND _id IN (${toRemove.map((c) => `'${c}'`).join(', ')})`
|
`DELETE FROM ${translateDomain(domain)} WHERE "workspaceId" = '${ws.workspace}' AND _id IN (${part.map((c) => `'${c}'`).join(', ')})`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
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, 100)
|
||||||
const values: DBDoc[] = []
|
const values: DBDoc[] = []
|
||||||
for (let i = 0; i < part.length; i++) {
|
for (let i = 0; i < part.length; i++) {
|
||||||
const doc = part[i]
|
const doc = part[i]
|
||||||
const d = convertDoc(domain, doc, ws.workspace)
|
const d = convertDoc(domain, doc, ws.workspace)
|
||||||
values.push(d)
|
values.push(d)
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
await retryTxn(pgClient, async (client) => {
|
await retryTxn(pgClient, async (client) => {
|
||||||
await client`INSERT INTO ${client(translateDomain(domain))} ${client(values, insertFields)}`
|
await client`INSERT INTO ${client(translateDomain(domain))} ${client(values, insertFields)}`
|
||||||
})
|
})
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Error when insert', domain, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ export async function createTables (client: postgres.Sql, domains: string[]): Pr
|
|||||||
async function getTableSchema (client: postgres.Sql, domain: string): Promise<void> {
|
async function getTableSchema (client: postgres.Sql, domain: string): Promise<void> {
|
||||||
const res = await client.unsafe(`SELECT column_name, data_type, is_nullable
|
const res = await client.unsafe(`SELECT column_name, data_type, is_nullable
|
||||||
FROM information_schema.columns
|
FROM information_schema.columns
|
||||||
WHERE table_name = '${domain}' ORDER BY ordinal_position ASC;
|
WHERE table_name = '${domain}' and table_schema = 'public' ORDER BY ordinal_position ASC;
|
||||||
`)
|
`)
|
||||||
|
|
||||||
const schema: Schema = {}
|
const schema: Schema = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user