1
0
Fork 0
mirror of synced 2024-09-21 20:01:32 +12:00

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 () => { 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 export default migration

View file

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