Add migration
This commit is contained in:
parent
e1c37e75a4
commit
4a1b99a9dc
|
@ -1,5 +1,26 @@
|
|||
import { SEPARATOR, context } from "@budibase/backend-core"
|
||||
import { allLinkDocs } from "../../db/utils"
|
||||
|
||||
const migration = async () => {
|
||||
// Add your migration logic here
|
||||
const linkDocs = await allLinkDocs()
|
||||
|
||||
const docsToUpdate = []
|
||||
for (const linkDoc of linkDocs) {
|
||||
if (linkDoc.tableId) {
|
||||
// It already had the required data
|
||||
continue
|
||||
}
|
||||
|
||||
linkDoc.tableId = [linkDoc.doc1.tableId, linkDoc.doc2.tableId]
|
||||
.sort()
|
||||
.join(SEPARATOR)
|
||||
docsToUpdate.push(linkDoc)
|
||||
}
|
||||
|
||||
if (docsToUpdate.length) {
|
||||
const db = context.getAppDB()
|
||||
await db.bulkDocs(docsToUpdate)
|
||||
}
|
||||
}
|
||||
|
||||
export default migration
|
||||
|
|
|
@ -8,6 +8,7 @@ export interface LinkInfo {
|
|||
|
||||
export interface LinkDocument extends Document {
|
||||
type: string
|
||||
tableId: string
|
||||
doc1: LinkInfo
|
||||
doc2: LinkInfo
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue