Addressing PR comments.
This commit is contained in:
parent
94b85eeed0
commit
06d6d84b55
|
@ -5,13 +5,12 @@ import { DocumentType } from "@budibase/types"
|
||||||
enum ReplicationDirection {
|
enum ReplicationDirection {
|
||||||
TO_PRODUCTION = "toProduction",
|
TO_PRODUCTION = "toProduction",
|
||||||
TO_DEV = "toDev",
|
TO_DEV = "toDev",
|
||||||
UNKNOWN = "unknown",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Replication {
|
class Replication {
|
||||||
source: PouchDB.Database
|
source: PouchDB.Database
|
||||||
target: PouchDB.Database
|
target: PouchDB.Database
|
||||||
direction: ReplicationDirection
|
direction: ReplicationDirection | undefined
|
||||||
|
|
||||||
constructor({ source, target }: { source: string; target: string }) {
|
constructor({ source, target }: { source: string; target: string }) {
|
||||||
this.source = getPouchDB(source)
|
this.source = getPouchDB(source)
|
||||||
|
@ -26,8 +25,6 @@ class Replication {
|
||||||
target.startsWith(DocumentType.APP_DEV)
|
target.startsWith(DocumentType.APP_DEV)
|
||||||
) {
|
) {
|
||||||
this.direction = ReplicationDirection.TO_DEV
|
this.direction = ReplicationDirection.TO_DEV
|
||||||
} else {
|
|
||||||
this.direction = ReplicationDirection.UNKNOWN
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -323,14 +323,16 @@ export class DatabaseImpl implements Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks design document is accurate (cleans up tables)
|
// checks design document is accurate (cleans up tables)
|
||||||
async sqlCleanup(): Promise<void> {
|
// this will check the design document and remove anything from
|
||||||
|
// disk which is not supposed to be there
|
||||||
|
async sqlDiskCleanup(): Promise<void> {
|
||||||
const dbName = this.name
|
const dbName = this.name
|
||||||
const url = `/${dbName}/_cleanup`
|
const url = `/${dbName}/_cleanup`
|
||||||
return await this._sqlQuery<void>(url, "POST")
|
return await this._sqlQuery<void>(url, "POST")
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes a document from sqlite
|
// removes a document from sqlite
|
||||||
async sqlPurge(docIds: string[] | string): Promise<void> {
|
async sqlPurgeDocument(docIds: string[] | string): Promise<void> {
|
||||||
if (!Array.isArray(docIds)) {
|
if (!Array.isArray(docIds)) {
|
||||||
docIds = [docIds]
|
docIds = [docIds]
|
||||||
}
|
}
|
||||||
|
@ -359,7 +361,7 @@ export class DatabaseImpl implements Database {
|
||||||
)
|
)
|
||||||
await this.remove(SQLITE_DESIGN_DOC_ID, definition._rev)
|
await this.remove(SQLITE_DESIGN_DOC_ID, definition._rev)
|
||||||
} finally {
|
} finally {
|
||||||
await this.sqlCleanup()
|
await this.sqlDiskCleanup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return await this.nano().db.destroy(this.name)
|
return await this.nano().db.destroy(this.name)
|
||||||
|
|
|
@ -56,19 +56,16 @@ export class DDInstrumentedDatabase implements Database {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove(idOrDoc: Document): Promise<DocumentDestroyResponse>
|
||||||
|
remove(idOrDoc: string, rev?: string): Promise<DocumentDestroyResponse>
|
||||||
remove(
|
remove(
|
||||||
id: string | Document,
|
idOrDoc: string | Document,
|
||||||
rev?: string | undefined
|
rev?: string
|
||||||
): Promise<DocumentDestroyResponse> {
|
): Promise<DocumentDestroyResponse> {
|
||||||
return tracer.trace("db.remove", span => {
|
return tracer.trace("db.remove", span => {
|
||||||
span?.addTags({ db_name: this.name, doc_id: id })
|
span?.addTags({ db_name: this.name, doc_id: idOrDoc })
|
||||||
if (typeof id === "object") {
|
const id: string = typeof idOrDoc === "object" ? idOrDoc._id! : idOrDoc
|
||||||
return this.db.remove(id)
|
return this.db.remove(id, rev)
|
||||||
} else if (rev) {
|
|
||||||
return this.db.remove(id, rev)
|
|
||||||
} else {
|
|
||||||
throw new Error("No revision supplied for removal")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,17 +164,17 @@ export class DDInstrumentedDatabase implements Database {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlPurge(docIds: string[] | string): Promise<void> {
|
sqlPurgeDocument(docIds: string[] | string): Promise<void> {
|
||||||
return tracer.trace("db.sqlPurge", span => {
|
return tracer.trace("db.sqlPurgeDocument", span => {
|
||||||
span?.addTags({ db_name: this.name })
|
span?.addTags({ db_name: this.name })
|
||||||
return this.db.sqlPurge(docIds)
|
return this.db.sqlPurgeDocument(docIds)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlCleanup(): Promise<void> {
|
sqlDiskCleanup(): Promise<void> {
|
||||||
return tracer.trace("db.sqlCleanup", span => {
|
return tracer.trace("db.sqlDiskCleanup", span => {
|
||||||
span?.addTags({ db_name: this.name })
|
span?.addTags({ db_name: this.name })
|
||||||
return this.db.sqlCleanup()
|
return this.db.sqlDiskCleanup()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ export async function removeTable(table: Table) {
|
||||||
delete definition.sql.tables[table._id!]
|
delete definition.sql.tables[table._id!]
|
||||||
await db.put(definition)
|
await db.put(definition)
|
||||||
// make sure SQS is cleaned up, tables removed
|
// make sure SQS is cleaned up, tables removed
|
||||||
await db.sqlCleanup()
|
await db.sqlDiskCleanup()
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err?.status === 404) {
|
if (err?.status === 404) {
|
||||||
|
|
|
@ -146,8 +146,8 @@ export interface Database {
|
||||||
sql: string,
|
sql: string,
|
||||||
parameters?: SqlQueryBinding
|
parameters?: SqlQueryBinding
|
||||||
): Promise<T[]>
|
): Promise<T[]>
|
||||||
sqlPurge(docIds: string[] | string): Promise<void>
|
sqlPurgeDocument(docIds: string[] | string): Promise<void>
|
||||||
sqlCleanup(): Promise<void>
|
sqlDiskCleanup(): Promise<void>
|
||||||
allDocs<T extends Document | RowValue>(
|
allDocs<T extends Document | RowValue>(
|
||||||
params: DatabaseQueryOpts
|
params: DatabaseQueryOpts
|
||||||
): Promise<AllDocsResponse<T>>
|
): Promise<AllDocsResponse<T>>
|
||||||
|
|
Loading…
Reference in New Issue