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 { dangerousGetDB, closeDB } from "."
|
||||||
|
import { DocumentType } from "./constants"
|
||||||
|
|
||||||
class Replication {
|
class Replication {
|
||||||
source: any
|
source: any
|
||||||
|
@ -53,6 +54,14 @@ class Replication {
|
||||||
return this.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
|
* Rollback the target DB back to the state of the source DB
|
||||||
*/
|
*/
|
||||||
|
@ -60,6 +69,7 @@ class Replication {
|
||||||
await this.target.destroy()
|
await this.target.destroy()
|
||||||
// Recreate the DB again
|
// Recreate the DB again
|
||||||
this.target = dangerousGetDB(this.target.name)
|
this.target = dangerousGetDB(this.target.name)
|
||||||
|
// take the opportunity to remove deleted tombstones
|
||||||
await this.replicate()
|
await this.replicate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -553,11 +553,7 @@ export const sync = async (ctx: any, next: any) => {
|
||||||
})
|
})
|
||||||
let error
|
let error
|
||||||
try {
|
try {
|
||||||
await replication.replicate({
|
await replication.replicate(replication.appReplicateOpts())
|
||||||
filter: function (doc: any) {
|
|
||||||
return doc._id !== DocumentType.APP_METADATA
|
|
||||||
},
|
|
||||||
})
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error = err
|
error = err
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {
|
||||||
getAppId,
|
getAppId,
|
||||||
getAppDB,
|
getAppDB,
|
||||||
getProdAppDB,
|
getProdAppDB,
|
||||||
|
getDevAppDB,
|
||||||
} from "@budibase/backend-core/context"
|
} from "@budibase/backend-core/context"
|
||||||
import { quotas } from "@budibase/pro"
|
import { quotas } from "@budibase/pro"
|
||||||
import { events } from "@budibase/backend-core"
|
import { events } from "@budibase/backend-core"
|
||||||
|
@ -110,17 +111,29 @@ async function deployApp(deployment: any) {
|
||||||
target: productionAppId,
|
target: productionAppId,
|
||||||
}
|
}
|
||||||
replication = new Replication(config)
|
replication = new Replication(config)
|
||||||
|
const devDb = getDevAppDB()
|
||||||
|
console.log("Compacting development DB")
|
||||||
|
await devDb.compact()
|
||||||
console.log("Replication object created")
|
console.log("Replication object created")
|
||||||
await replication.replicate()
|
await replication.replicate(replication.appReplicateOpts())
|
||||||
console.log("replication complete.. replacing app meta doc")
|
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 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
|
deployment.appUrl = appDoc.url
|
||||||
|
|
||||||
appDoc.appId = productionAppId
|
appDoc.appId = productionAppId
|
||||||
appDoc.instance._id = productionAppId
|
appDoc.instance._id = productionAppId
|
||||||
|
// remove automation errors if they exist
|
||||||
|
delete appDoc.automationErrors
|
||||||
await db.put(appDoc)
|
await db.put(appDoc)
|
||||||
await appCache.invalidateAppMetadata(productionAppId)
|
await appCache.invalidateAppMetadata(productionAppId)
|
||||||
console.log("New app doc written successfully.")
|
console.log("New app doc written successfully.")
|
||||||
|
|
Loading…
Reference in New Issue