1
0
Fork 0
mirror of synced 2024-09-10 06:26:02 +12:00

Fixing an issue with cleanup, making sure the correct app is cleaned up on deletion.

This commit is contained in:
mike12345567 2024-05-09 18:33:29 +01:00
parent fd7f6455bd
commit a3d079f847
3 changed files with 36 additions and 6 deletions

View file

@ -1,14 +1,34 @@
import PouchDB from "pouchdb"
import { getPouchDB, closePouchDB } from "./couch"
import { DocumentType } from "../constants"
import { DocumentType } from "@budibase/types"
enum ReplicationDirection {
TO_PRODUCTION = "toProduction",
TO_DEV = "toDev",
UNKNOWN = "unknown",
}
class Replication {
source: PouchDB.Database
target: PouchDB.Database
direction: ReplicationDirection
constructor({ source, target }: { source: string; target: string }) {
this.source = getPouchDB(source)
this.target = getPouchDB(target)
if (
source.startsWith(DocumentType.APP_DEV) &&
target.startsWith(DocumentType.APP)
) {
this.direction = ReplicationDirection.TO_PRODUCTION
} else if (
source.startsWith(DocumentType.APP) &&
target.startsWith(DocumentType.APP_DEV)
) {
this.direction = ReplicationDirection.TO_DEV
} else {
this.direction = ReplicationDirection.UNKNOWN
}
}
async close() {
@ -40,12 +60,18 @@ class Replication {
}
const filter = opts.filter
const direction = this.direction
const toDev = direction === ReplicationDirection.TO_DEV
delete opts.filter
return {
...opts,
filter: (doc: any, params: any) => {
if (doc._id && doc._id.startsWith(DocumentType.AUTOMATION_LOG)) {
// don't sync design documents
if (toDev && doc._id?.startsWith("_design")) {
return false
}
if (doc._id?.startsWith(DocumentType.AUTOMATION_LOG)) {
return false
}
if (doc._id === DocumentType.APP_METADATA) {

View file

@ -591,7 +591,7 @@ async function destroyApp(ctx: UserCtx) {
async function preDestroyApp(ctx: UserCtx) {
if (env.SQS_SEARCH_ENABLE) {
await sdk.tables.sqs.cleanupApp()
await sdk.tables.sqs.cleanupApp(ctx.params.appId)
}
const { rows } = await getUniqueRows([ctx.params.appId])
ctx.rowCount = rows.length

View file

@ -1,4 +1,8 @@
import { context, SQLITE_DESIGN_DOC_ID } from "@budibase/backend-core"
import {
context,
SQLITE_DESIGN_DOC_ID,
db as dbCore,
} from "@budibase/backend-core"
import {
FieldType,
RelationshipFieldMetadata,
@ -156,8 +160,8 @@ export async function removeTable(table: Table) {
}
}
export async function cleanupApp() {
const db = context.getAppDB()
export async function cleanupApp(appId: string) {
const db = dbCore.getDB(appId)
if (!(await db.exists())) {
throw new Error("Cleanup must be preformed before app deletion.")
}