Fix backup (#7134)

This commit is contained in:
Denis Bykhov 2024-11-08 15:13:18 +05:00 committed by GitHub
parent d88f361589
commit a05e2a31d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View File

@ -1085,17 +1085,17 @@ abstract class PostgresAdapterBase implements DbAdapter {
if (!initialized) {
if (recheck === true) {
await this.retryTxn(client, async (client) => {
await client`UPDATE ${client(translateDomain(domain))} SET jsonb_set(data, '{%hash%}', 'NULL', true) WHERE "workspaceId" = ${this.workspaceId.name} AND data ->> '%hash%' IS NOT NULL`
await client`UPDATE ${client(translateDomain(domain))} SET '%hash%' = NULL WHERE "workspaceId" = ${this.workspaceId.name} AND '%hash%' IS NOT NULL`
})
}
await init('_id, data', "data ->> '%hash%' IS NOT NULL AND data ->> '%hash%' <> ''")
await init('_id, data', "'%hash%' IS NOT NULL AND '%hash%' <> ''")
initialized = true
}
let docs = await ctx.with('next', { mode }, async () => await next(50))
if (docs.length === 0 && mode === 'hashed') {
await close(cursorName)
mode = 'non_hashed'
await init('*', "data ->> '%hash%' IS NULL OR data ->> '%hash%' = ''")
await init('*', "'%hash%' IS NULL OR '%hash%' = ''")
docs = await ctx.with('next', { mode }, async () => await next(50))
}
if (docs.length === 0) {
@ -1155,7 +1155,7 @@ abstract class PostgresAdapterBase implements DbAdapter {
const connection = (await this.getConnection(ctx)) ?? this.client
const res =
await connection`SELECT * FROM ${connection(translateDomain(domain))} WHERE _id = ANY(${docs}) AND "workspaceId" = ${this.workspaceId.name}`
return res as any as Doc[]
return res.map((p) => parseDocWithProjection(p as any))
})
}

View File

@ -388,7 +388,7 @@ export class DBCollectionHelper implements DomainHelperOperations {
}
}
export function parseDocWithProjection<T extends Doc> (doc: DBDoc, projection: Projection<T> | undefined): T {
export function parseDocWithProjection<T extends Doc> (doc: DBDoc, projection?: Projection<T> | undefined): T {
const { workspaceId, data, ...rest } = doc
for (const key in rest) {
if ((rest as any)[key] === 'NULL' || (rest as any)[key] === null) {