|
|
|
@ -1,9 +1,6 @@
|
|
|
|
|
const Api = require('nocodb-sdk').Api; |
|
|
|
|
const { UITypes } = require('nocodb-sdk'); |
|
|
|
|
const jsonfile = require("jsonfile"); |
|
|
|
|
const dayjs = require("dayjs"); |
|
|
|
|
const axios = require("axios"); |
|
|
|
|
const FormData = require("form-data"); |
|
|
|
|
|
|
|
|
|
let api = {} |
|
|
|
|
let ncIn = jsonfile.readFileSync('sample.json') |
|
|
|
@ -13,6 +10,8 @@ let lookup = []
|
|
|
|
|
let rollup = [] |
|
|
|
|
let formula = [] |
|
|
|
|
let ncTables = {} |
|
|
|
|
let rootLinks = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ncConfig = { |
|
|
|
|
srcProject: "sample", |
|
|
|
@ -79,7 +78,6 @@ async function createFormula() {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let rootLinks = [] |
|
|
|
|
async function createLinks() { |
|
|
|
|
console.log(`createLinks`) |
|
|
|
|
for (let i = 0; i < link.length; i++) { |
|
|
|
@ -280,10 +278,15 @@ async function restoreBaseData() {
|
|
|
|
|
let tblId = ncTables[tblSchema.id].id; |
|
|
|
|
let pk = tblSchema.columns.find(a => a.pk).title |
|
|
|
|
|
|
|
|
|
// fixme: iterate page information
|
|
|
|
|
let moreRecords = true; |
|
|
|
|
let offset = 0, limit = 25; |
|
|
|
|
|
|
|
|
|
while(moreRecords) { |
|
|
|
|
let recList = await api.dbTableRow.list("nc", ncConfig.srcProject, tblSchema.title, {}, { |
|
|
|
|
query: { limit: 500 } |
|
|
|
|
query: { limit: limit, offset: offset } |
|
|
|
|
}) |
|
|
|
|
moreRecords = !recList.pageInfo.isLastPage |
|
|
|
|
offset += limit |
|
|
|
|
|
|
|
|
|
for (let recCnt = 0; recCnt < recList.list.length; recCnt++) { |
|
|
|
|
let record = await api.dbTableRow.read("nc", ncConfig.srcProject, tblSchema.title, recList.list[recCnt][pk]) |
|
|
|
@ -300,6 +303,7 @@ async function restoreBaseData() {
|
|
|
|
|
await api.dbTableRow.create("nc", ncConfig.projectName, tblSchema.title, record) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function restoreLinks() { |
|
|
|
@ -307,16 +311,20 @@ async function restoreLinks() {
|
|
|
|
|
|
|
|
|
|
for(let i=0; i<rootLinks.length; i++) { |
|
|
|
|
let pk = rootLinks[i].linkSrcTbl.columns.find(a => a.pk).title |
|
|
|
|
let moreRecords = true; |
|
|
|
|
let offset = 0, limit = 25; |
|
|
|
|
|
|
|
|
|
// fixme: iterate page information
|
|
|
|
|
while(moreRecords) { |
|
|
|
|
let recList = await api.dbTableRow.list("nc", ncConfig.srcProject, rootLinks[i].linkSrcTbl.title, {}, { |
|
|
|
|
query: { limit: 500 } |
|
|
|
|
query: { limit: limit, offset: offset } |
|
|
|
|
}) |
|
|
|
|
moreRecords = !recList.pageInfo.isLastPage |
|
|
|
|
offset += limit |
|
|
|
|
|
|
|
|
|
for (let recCnt = 0; recCnt < recList.list.length; recCnt++) { |
|
|
|
|
let record = await api.dbTableRow.read("nc", ncConfig.srcProject, rootLinks[i].linkSrcTbl.title, recList.list[recCnt][pk]) |
|
|
|
|
let linkField = record[rootLinks[i].linkColumn.title]; |
|
|
|
|
if(linkField.length) { |
|
|
|
|
if (linkField.length) { |
|
|
|
|
await api.dbTableRow.nestedAdd("nc", ncConfig.projectName, rootLinks[i].linkSrcTbl.title, |
|
|
|
|
record[pk], |
|
|
|
|
rootLinks[i].linkColumn.colOptions.type, |
|
|
|
@ -326,6 +334,7 @@ async function restoreLinks() {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|