diff --git a/packages/server/src/appMigrations/migrations/20231229122514_update_link_documents.ts b/packages/server/src/appMigrations/migrations/20231229122514_update_link_documents.ts index f23f72e070..e1e1d4efc6 100644 --- a/packages/server/src/appMigrations/migrations/20231229122514_update_link_documents.ts +++ b/packages/server/src/appMigrations/migrations/20231229122514_update_link_documents.ts @@ -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 diff --git a/packages/types/src/documents/app/links.ts b/packages/types/src/documents/app/links.ts index ae7e4de78e..2a9595d99f 100644 --- a/packages/types/src/documents/app/links.ts +++ b/packages/types/src/documents/app/links.ts @@ -8,6 +8,7 @@ export interface LinkInfo { export interface LinkDocument extends Document { type: string + tableId: string doc1: LinkInfo doc2: LinkInfo }