diff --git a/packages/server/scripts/load/create-many-relationships.js b/packages/server/scripts/load/create-many-relationships.js index 07861cc632..13f861ec0b 100755 --- a/packages/server/scripts/load/create-many-relationships.js +++ b/packages/server/scripts/load/create-many-relationships.js @@ -5,6 +5,7 @@ const { createRow, createTable, getApp, + getRows, } = require("./utils") const Chance = require("chance") @@ -122,14 +123,16 @@ async function run() { primaryDisplay: "Name", }) - const subjects = await batchCreate( - apiKey, - appId, - subjectTable, - Array.from({ length: SUBJECT_COUNT }).map(() => ({ - Name: generator.profession(), - })) - ) + const subjects = useExistingApp + ? await getRows(apiKey, appId, subjectTable._id) + : await batchCreate( + apiKey, + appId, + subjectTable, + Array.from({ length: SUBJECT_COUNT }).map(() => ({ + Name: generator.profession(), + })) + ) const gradesTable = await upsertTable(appId, "Grades", { schema: { diff --git a/packages/server/scripts/load/utils.js b/packages/server/scripts/load/utils.js index 2b789cde52..1dabdcec9a 100644 --- a/packages/server/scripts/load/utils.js +++ b/packages/server/scripts/load/utils.js @@ -88,6 +88,12 @@ exports.createRow = async (apiKey, appId, table, body) => { return (await res.json()).data } +exports.getRows = async (apiKey, appId, tableId) => { + const url = `${URL_TABLE}/${tableId}/rows/search` + const res = await request(apiKey, url, "POST", {}, appId) + return (await res.json()).data +} + exports.createTable = async (apiKey, appId, config) => { const res = await request(apiKey, URL_TABLE, "POST", config, appId) const json = await res.json()