Adding compaction before each replication to try to reduce size of database, as well as removing the possibility of app metadata being in conflict as per issue #7494.
This commit is contained in:
parent
1ee7382f84
commit
2d183e0c6c
|
@ -1,4 +1,5 @@
|
|||
import { dangerousGetDB, closeDB } from "."
|
||||
import { DocumentType } from "./constants"
|
||||
|
||||
class Replication {
|
||||
source: any
|
||||
|
@ -53,6 +54,14 @@ class Replication {
|
|||
return this.replication
|
||||
}
|
||||
|
||||
appReplicateOpts() {
|
||||
return {
|
||||
filter: (doc: any) => {
|
||||
return doc._id !== DocumentType.APP_METADATA
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback the target DB back to the state of the source DB
|
||||
*/
|
||||
|
@ -60,6 +69,7 @@ class Replication {
|
|||
await this.target.destroy()
|
||||
// Recreate the DB again
|
||||
this.target = dangerousGetDB(this.target.name)
|
||||
// take the opportunity to remove deleted tombstones
|
||||
await this.replicate()
|
||||
}
|
||||
|
||||
|
|
|
@ -553,11 +553,7 @@ export const sync = async (ctx: any, next: any) => {
|
|||
})
|
||||
let error
|
||||
try {
|
||||
await replication.replicate({
|
||||
filter: function (doc: any) {
|
||||
return doc._id !== DocumentType.APP_METADATA
|
||||
},
|
||||
})
|
||||
await replication.replicate(replication.appReplicateOpts())
|
||||
} catch (err) {
|
||||
error = err
|
||||
} finally {
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
getAppId,
|
||||
getAppDB,
|
||||
getProdAppDB,
|
||||
getDevAppDB,
|
||||
} from "@budibase/backend-core/context"
|
||||
import { quotas } from "@budibase/pro"
|
||||
import { events } from "@budibase/backend-core"
|
||||
|
@ -110,17 +111,29 @@ async function deployApp(deployment: any) {
|
|||
target: productionAppId,
|
||||
}
|
||||
replication = new Replication(config)
|
||||
|
||||
const devDb = getDevAppDB()
|
||||
console.log("Compacting development DB")
|
||||
await devDb.compact()
|
||||
console.log("Replication object created")
|
||||
await replication.replicate()
|
||||
await replication.replicate(replication.appReplicateOpts())
|
||||
console.log("replication complete.. replacing app meta doc")
|
||||
// app metadata is excluded as it is likely to be in conflict
|
||||
// replicate the app metadata document manually
|
||||
const db = getProdAppDB()
|
||||
const appDoc = await db.get(DocumentType.APP_METADATA)
|
||||
const appDoc = await devDb.get(DocumentType.APP_METADATA)
|
||||
try {
|
||||
const prodAppDoc = await db.get(DocumentType.APP_METADATA)
|
||||
appDoc._rev = prodAppDoc._rev
|
||||
} catch (err) {
|
||||
// ignore the error - doesn't exist
|
||||
}
|
||||
|
||||
// switch to production app ID
|
||||
deployment.appUrl = appDoc.url
|
||||
|
||||
appDoc.appId = productionAppId
|
||||
appDoc.instance._id = productionAppId
|
||||
// remove automation errors if they exist
|
||||
delete appDoc.automationErrors
|
||||
await db.put(appDoc)
|
||||
await appCache.invalidateAppMetadata(productionAppId)
|
||||
console.log("New app doc written successfully.")
|
||||
|
|
Loading…
Reference in New Issue