Some type updates and processor handling for backup document being created before backup/restore occurs.
This commit is contained in:
parent
e5ebd97ecc
commit
6112d097af
|
@ -1,6 +1,6 @@
|
|||
import { backups } from "@budibase/pro"
|
||||
import { objectStore, tenancy, db as dbCore } from "@budibase/backend-core"
|
||||
import { AppBackupQueueData } from "@budibase/types"
|
||||
import { db as dbCore, objectStore, tenancy } from "@budibase/backend-core"
|
||||
import { AppBackupQueueData, AppBackupStatus } from "@budibase/types"
|
||||
import { exportApp } from "./exports"
|
||||
import { importApp } from "./imports"
|
||||
import { calculateBackupStats } from "../statistics"
|
||||
|
@ -42,6 +42,11 @@ async function importProcessor(job: Job) {
|
|||
await removeExistingApp(devAppId)
|
||||
await performImport(backupTarPath)
|
||||
}
|
||||
await backups.updateRestoreStatus(
|
||||
data.docId,
|
||||
data.docRev,
|
||||
AppBackupStatus.COMPLETE
|
||||
)
|
||||
fs.rmSync(backupTarPath)
|
||||
})
|
||||
}
|
||||
|
@ -64,13 +69,6 @@ async function exportProcessor(job: Job) {
|
|||
filename = `${tenantId}/${filename}`
|
||||
}
|
||||
const bucket = objectStore.ObjectStoreBuckets.BACKUPS
|
||||
const metadata = {
|
||||
appId: prodAppId,
|
||||
timestamp,
|
||||
trigger,
|
||||
name,
|
||||
contents,
|
||||
}
|
||||
await objectStore.upload({
|
||||
path: tarPath,
|
||||
type: "application/gzip",
|
||||
|
@ -83,7 +81,13 @@ async function exportProcessor(job: Job) {
|
|||
appId: prodAppId,
|
||||
},
|
||||
})
|
||||
await backups.storeAppBackupMetadata(filename, metadata)
|
||||
await backups.updateBackupStatus(
|
||||
data.docId,
|
||||
data.docRev,
|
||||
AppBackupStatus.COMPLETE,
|
||||
contents,
|
||||
filename
|
||||
)
|
||||
// clear up the tarball after uploading it
|
||||
fs.rmSync(tarPath)
|
||||
})
|
||||
|
|
|
@ -1,31 +1,41 @@
|
|||
import { Document } from "../document"
|
||||
|
||||
export enum AppBackupType {
|
||||
BACKUP = "backup",
|
||||
RESTORE = "restore",
|
||||
}
|
||||
|
||||
export enum AppBackupStatus {
|
||||
STARTED = "started",
|
||||
COMPLETE = "complete",
|
||||
FAILED = "failed",
|
||||
}
|
||||
|
||||
export enum AppBackupTrigger {
|
||||
PUBLISH = "publish",
|
||||
MANUAL = "manual",
|
||||
SCHEDULED = "scheduled",
|
||||
}
|
||||
|
||||
export enum AppBackupEventType {
|
||||
EXPORT = "export",
|
||||
IMPORT = "import",
|
||||
export interface AppBackupContents {
|
||||
datasources: string[]
|
||||
screens: string[]
|
||||
automations: string[]
|
||||
}
|
||||
|
||||
export interface AppBackupMetadata {
|
||||
appId: string
|
||||
trigger: AppBackupTrigger
|
||||
trigger?: AppBackupTrigger
|
||||
type: AppBackupType
|
||||
status: AppBackupStatus
|
||||
name?: string
|
||||
createdBy?: string
|
||||
timestamp: string
|
||||
contents: {
|
||||
datasources: string[]
|
||||
screens: string[]
|
||||
automations: string[]
|
||||
}
|
||||
contents?: AppBackupContents
|
||||
}
|
||||
|
||||
export interface AppBackup extends Document, AppBackupMetadata {
|
||||
filename: string
|
||||
filename?: string
|
||||
}
|
||||
|
||||
export type AppBackupFetchOpts = {
|
||||
|
@ -38,8 +48,9 @@ export type AppBackupFetchOpts = {
|
|||
}
|
||||
|
||||
export interface AppBackupQueueData {
|
||||
eventType: AppBackupEventType
|
||||
appId: string
|
||||
docId: string
|
||||
docRev: string
|
||||
export?: {
|
||||
trigger: AppBackupTrigger
|
||||
name?: string
|
||||
|
@ -47,5 +58,6 @@ export interface AppBackupQueueData {
|
|||
}
|
||||
import?: {
|
||||
backupId: string
|
||||
createdBy?: string
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue