Add migration

This commit is contained in:
Adria Navarro 2023-12-29 13:32:45 +01:00
parent e1c37e75a4
commit 4a1b99a9dc
2 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -8,6 +8,7 @@ export interface LinkInfo {
export interface LinkDocument extends Document {
type: string
tableId: string
doc1: LinkInfo
doc2: LinkInfo
}