From a6de5a4fa1f8affe5b783126d7475a0f84614d6e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 2 Dec 2021 16:17:10 +0000 Subject: [PATCH] Exporting date and auto id field, but not importing autocolumns when table is created. --- packages/server/src/api/controllers/table/utils.js | 1 + packages/server/src/api/controllers/view/index.js | 13 +++++++------ packages/server/src/utilities/csvParser.js | 7 +++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/server/src/api/controllers/table/utils.js b/packages/server/src/api/controllers/table/utils.js index 0623fc64b5..e4086e8071 100644 --- a/packages/server/src/api/controllers/table/utils.js +++ b/packages/server/src/api/controllers/table/utils.js @@ -75,6 +75,7 @@ exports.handleDataImport = async (appId, user, table, dataImport) => { if (!dataImport || !dataImport.csvString) { return table } + const db = new CouchDB(appId) // Populate the table with rows imported from CSV in a bulk update const data = await csvParser.transform({ diff --git a/packages/server/src/api/controllers/view/index.js b/packages/server/src/api/controllers/view/index.js index b4399f416d..9a844fedff 100644 --- a/packages/server/src/api/controllers/view/index.js +++ b/packages/server/src/api/controllers/view/index.js @@ -5,6 +5,7 @@ const exporters = require("./exporters") const { saveView, getView, getViews, deleteView } = require("./utils") const { fetchView } = require("../row") const { getTable } = require("../table/utils") +const { FieldTypes } = require("../../../constants") exports.fetch = async ctx => { const db = new CouchDB(ctx.appId) @@ -86,15 +87,15 @@ exports.exportView = async ctx => { schema = table.schema } - // remove any auto columns - const autocolumns = Object.entries(schema) - .filter(entry => entry[1].autocolumn) + // remove any relationships + const relationships = Object.entries(schema) + .filter(entry => entry[1].type === FieldTypes.LINK) .map(entry => entry[0]) rows.forEach(row => { - autocolumns.forEach(column => delete row[column]) + relationships.forEach(column => delete row[column]) }) - // delete auto columns from schema - autocolumns.forEach(column => { + // delete relationships from schema + relationships.forEach(column => { delete schema[column] }) diff --git a/packages/server/src/utilities/csvParser.js b/packages/server/src/utilities/csvParser.js index c548a71758..8f9b3373c9 100644 --- a/packages/server/src/utilities/csvParser.js +++ b/packages/server/src/utilities/csvParser.js @@ -102,8 +102,11 @@ async function transform({ schema, csvString, existingTable }) { schema = updateSchema({ schema, existingTable }) } - for (let key of Object.keys(schema)) { - colParser[key] = PARSERS[schema[key].type] || schema[key].type + for (let [key, field] of Object.entries(schema)) { + // don't import data to auto columns + if (!field.autocolumn) { + colParser[key] = PARSERS[field.type] || field.type + } } try {