@budibase/server 2.0.30-alpha.14 → 2.0.30-alpha.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builder/assets/backups-default.8c011f1b.png +0 -0
- package/builder/assets/{index.099ad307.js → index.7ebb4fb6.js} +333 -329
- package/builder/assets/{index.acdbfe62.css → index.b15ffe95.css} +1 -1
- package/builder/index.html +2 -2
- package/coverage/clover.xml +254 -313
- package/coverage/coverage-final.json +15 -17
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +74 -62
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +17 -32
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +12 -9
- package/coverage/lcov-report/api/controllers/table/external.js.html +10 -10
- package/coverage/lcov-report/api/controllers/table/index.html +16 -16
- package/coverage/lcov-report/api/controllers/table/index.js.html +5 -5
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +3 -3
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +3 -3
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +5 -20
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +6 -6
- package/coverage/lcov-report/automations/bullboard.js.html +17 -92
- package/coverage/lcov-report/automations/index.html +18 -18
- package/coverage/lcov-report/automations/index.js.html +5 -5
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +5 -5
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +6 -18
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +19 -19
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +35 -308
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +62 -62
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/builder.js.html +1 -1
- package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +1 -1
- package/coverage/lcov-report/utilities/index.html +1 -1
- package/coverage/lcov-report/utilities/index.js.html +1 -1
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +52 -52
- package/coverage/lcov-report/utilities/queue/index.html +21 -21
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +2 -2
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +451 -564
- package/dist/api/controllers/application.js +2 -5
- package/dist/api/controllers/backup.js +19 -13
- package/dist/api/controllers/cloud.js +38 -35
- package/dist/api/controllers/deploy/index.js +11 -2
- package/dist/api/controllers/static/index.js +2 -2
- package/dist/api/controllers/table/bulkFormula.js +4 -3
- package/dist/api/controllers/table/external.js +5 -4
- package/dist/api/controllers/table/index.js +4 -4
- package/dist/api/controllers/table/internal.js +2 -1
- package/dist/api/controllers/table/utils.js +4 -48
- package/dist/api/controllers/view/index.js +2 -2
- package/dist/api/routes/backup.js +34 -7
- package/dist/api/routes/index.js +9 -4
- package/dist/app.js +14 -0
- package/dist/automations/automationUtils.js +2 -2
- package/dist/automations/bullboard.js +5 -33
- package/dist/automations/index.js +4 -4
- package/dist/automations/triggers.js +4 -4
- package/dist/automations/utils.js +13 -9
- package/dist/constants/index.js +2 -5
- package/dist/db/utils.js +10 -75
- package/dist/migrations/functions/backfill/app/tables.js +5 -8
- package/dist/package.json +11 -11
- package/dist/sdk/app/backups/constants.js +5 -0
- package/dist/sdk/app/backups/exports.js +172 -0
- package/dist/sdk/app/backups/imports.js +162 -0
- package/dist/sdk/app/backups/index.js +29 -0
- package/dist/sdk/app/backups/statistics.js +73 -0
- package/dist/sdk/app/tables/index.js +61 -0
- package/dist/sdk/index.js +15 -0
- package/dist/tests/utilities/TestConfiguration.js +4 -2
- package/dist/threads/automation.js +12 -17
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +3 -95
- package/dist/utilities/fileSystem/utilities.js +2 -1
- package/package.json +12 -12
- package/src/api/controllers/application.ts +3 -10
- package/src/api/controllers/{backup.js → backup.ts} +7 -7
- package/src/api/controllers/cloud.js +44 -40
- package/src/api/controllers/deploy/index.ts +20 -7
- package/src/api/controllers/static/index.ts +2 -2
- package/src/api/controllers/table/bulkFormula.js +4 -3
- package/src/api/controllers/table/external.js +4 -4
- package/src/api/controllers/table/index.js +4 -4
- package/src/api/controllers/table/internal.ts +3 -7
- package/src/api/controllers/table/utils.ts +1 -52
- package/src/api/controllers/view/index.js +2 -2
- package/src/api/routes/backup.ts +10 -0
- package/src/api/routes/index.ts +11 -5
- package/src/api/routes/tests/backup.spec.js +1 -1
- package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
- package/src/app.ts +15 -0
- package/src/automations/automationUtils.js +2 -2
- package/src/automations/bullboard.js +8 -33
- package/src/automations/index.js +4 -4
- package/src/automations/triggers.js +4 -4
- package/src/automations/utils.ts +12 -8
- package/src/constants/index.js +2 -6
- package/src/db/utils.js +17 -108
- package/src/definitions/automations.ts +0 -12
- package/src/migrations/functions/backfill/app/tables.ts +6 -13
- package/src/sdk/app/backups/constants.ts +2 -0
- package/src/sdk/app/backups/exports.ts +171 -0
- package/src/sdk/app/backups/imports.ts +168 -0
- package/src/sdk/app/backups/index.ts +9 -0
- package/src/sdk/app/backups/statistics.ts +77 -0
- package/src/sdk/app/tables/index.ts +60 -0
- package/src/sdk/index.ts +13 -0
- package/src/tests/utilities/TestConfiguration.js +5 -2
- package/src/threads/automation.ts +20 -27
- package/src/utilities/fileSystem/index.js +2 -119
- package/src/utilities/fileSystem/utilities.js +2 -0
- package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
- package/coverage/lcov-report/api/routes/backup.js.html +0 -115
- package/dist/automations/listeners.js +0 -102
- package/src/api/routes/backup.js +0 -10
- package/src/automations/listeners.ts +0 -78
|
@@ -12,14 +12,11 @@ const { budibaseTempDir } = require("../budibaseDir");
|
|
|
12
12
|
const fs = require("fs");
|
|
13
13
|
const { join } = require("path");
|
|
14
14
|
const uuid = require("uuid/v4");
|
|
15
|
-
const { doWithDB, dangerousGetDB, closeDB, } = require("@budibase/backend-core/db");
|
|
16
15
|
const { ObjectStoreBuckets } = require("../../constants");
|
|
17
|
-
const { upload, retrieve, retrieveToTmp,
|
|
16
|
+
const { upload, retrieve, retrieveToTmp, deleteFolder, downloadTarball, downloadTarballDirect, deleteFiles, } = require("./utilities");
|
|
18
17
|
const { updateClientLibrary } = require("./clientLibrary");
|
|
19
18
|
const { checkSlashesInUrl } = require("../");
|
|
20
19
|
const env = require("../../environment");
|
|
21
|
-
const { USER_METDATA_PREFIX, LINK_USER_METADATA_PREFIX, TABLE_ROW_PREFIX, } = require("../../db/utils");
|
|
22
|
-
const MemoryStream = require("memorystream");
|
|
23
20
|
const { getAppId } = require("@budibase/backend-core/context");
|
|
24
21
|
const tar = require("tar");
|
|
25
22
|
const fetch = require("node-fetch");
|
|
@@ -75,21 +72,6 @@ exports.checkDevelopmentEnvironment = () => {
|
|
|
75
72
|
process.exit(-1);
|
|
76
73
|
}
|
|
77
74
|
};
|
|
78
|
-
/**
|
|
79
|
-
* This function manages temporary template files which are stored by Koa.
|
|
80
|
-
* @param {Object} template The template object retrieved from the Koa context object.
|
|
81
|
-
* @returns {Object} Returns an fs read stream which can be loaded into the database.
|
|
82
|
-
*/
|
|
83
|
-
exports.getTemplateStream = (template) => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
-
if (template.file) {
|
|
85
|
-
return fs.createReadStream(template.file.path);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
const [type, name] = template.key.split("/");
|
|
89
|
-
const tmpPath = yield exports.downloadTemplate(type, name);
|
|
90
|
-
return fs.createReadStream(join(tmpPath, name, "db", "dump.txt"));
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
75
|
/**
|
|
94
76
|
* Used to retrieve a handlebars file from the system which will be used as a template.
|
|
95
77
|
* This is allowable as the template handlebars files should be static and identical across
|
|
@@ -111,83 +93,9 @@ exports.apiFileReturn = contents => {
|
|
|
111
93
|
fs.writeFileSync(path, contents);
|
|
112
94
|
return fs.createReadStream(path);
|
|
113
95
|
};
|
|
114
|
-
exports.
|
|
115
|
-
|
|
116
|
-
if (excludeRows) {
|
|
117
|
-
ids.push(TABLE_ROW_PREFIX);
|
|
118
|
-
}
|
|
119
|
-
return doc => !ids.map(key => doc._id.includes(key)).reduce((prev, curr) => prev || curr);
|
|
96
|
+
exports.streamFile = path => {
|
|
97
|
+
return fs.createReadStream(path);
|
|
120
98
|
};
|
|
121
|
-
/**
|
|
122
|
-
* Local utility to back up the database state for an app, excluding global user
|
|
123
|
-
* data or user relationships.
|
|
124
|
-
* @param {string} appId The app to backup
|
|
125
|
-
* @param {object} config Config to send to export DB
|
|
126
|
-
* @param {boolean} excludeRows Flag to state whether the export should include data.
|
|
127
|
-
* @returns {*} either a string or a stream of the backup
|
|
128
|
-
*/
|
|
129
|
-
const backupAppData = (appId, config, excludeRows) => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
|
-
return yield exports.exportDB(appId, Object.assign(Object.assign({}, config), { filter: exports.defineFilter(excludeRows) }));
|
|
131
|
-
});
|
|
132
|
-
/**
|
|
133
|
-
* Takes a copy of the database state for an app to the object store.
|
|
134
|
-
* @param {string} appId The ID of the app which is to be backed up.
|
|
135
|
-
* @param {string} backupName The name of the backup located in the object store.
|
|
136
|
-
* @return {*} a readable stream to the completed backup file
|
|
137
|
-
*/
|
|
138
|
-
exports.performBackup = (appId, backupName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
-
return yield backupAppData(appId, { exportName: backupName });
|
|
140
|
-
});
|
|
141
|
-
/**
|
|
142
|
-
* Streams a backup of the database state for an app
|
|
143
|
-
* @param {string} appId The ID of the app which is to be backed up.
|
|
144
|
-
* @param {boolean} excludeRows Flag to state whether the export should include data.
|
|
145
|
-
* @returns {*} a readable stream of the backup which is written in real time
|
|
146
|
-
*/
|
|
147
|
-
exports.streamBackup = (appId, excludeRows) => __awaiter(void 0, void 0, void 0, function* () {
|
|
148
|
-
return yield backupAppData(appId, { stream: true }, excludeRows);
|
|
149
|
-
});
|
|
150
|
-
/**
|
|
151
|
-
* Exports a DB to either file or a variable (memory).
|
|
152
|
-
* @param {string} dbName the DB which is to be exported.
|
|
153
|
-
* @param {string} exportName optional - provide a filename to write the backup to a file
|
|
154
|
-
* @param {boolean} stream optional - whether to perform a full backup
|
|
155
|
-
* @param {function} filter optional - a filter function to clear out any un-wanted docs.
|
|
156
|
-
* @return {*} either a readable stream or a string
|
|
157
|
-
*/
|
|
158
|
-
exports.exportDB = (dbName, { stream, filter, exportName } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
159
|
-
// streaming a DB dump is a bit more complicated, can't close DB
|
|
160
|
-
if (stream) {
|
|
161
|
-
const db = dangerousGetDB(dbName);
|
|
162
|
-
const memStream = new MemoryStream();
|
|
163
|
-
memStream.on("end", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
-
yield closeDB(db);
|
|
165
|
-
}));
|
|
166
|
-
db.dump(memStream, { filter });
|
|
167
|
-
return memStream;
|
|
168
|
-
}
|
|
169
|
-
return doWithDB(dbName, (db) => __awaiter(void 0, void 0, void 0, function* () {
|
|
170
|
-
// Write the dump to file if required
|
|
171
|
-
if (exportName) {
|
|
172
|
-
const path = join(budibaseTempDir(), exportName);
|
|
173
|
-
const writeStream = fs.createWriteStream(path);
|
|
174
|
-
yield db.dump(writeStream, { filter });
|
|
175
|
-
// Upload the dump to the object store if self hosted
|
|
176
|
-
if (env.SELF_HOSTED) {
|
|
177
|
-
yield streamUpload(ObjectStoreBuckets.BACKUPS, join(dbName, exportName), fs.createReadStream(path));
|
|
178
|
-
}
|
|
179
|
-
return fs.createReadStream(path);
|
|
180
|
-
}
|
|
181
|
-
// Stringify the dump in memory if required
|
|
182
|
-
const memStream = new MemoryStream();
|
|
183
|
-
let appString = "";
|
|
184
|
-
memStream.on("data", chunk => {
|
|
185
|
-
appString += chunk.toString();
|
|
186
|
-
});
|
|
187
|
-
yield db.dump(memStream, { filter });
|
|
188
|
-
return appString;
|
|
189
|
-
}));
|
|
190
|
-
});
|
|
191
99
|
/**
|
|
192
100
|
* Writes the provided contents to a temporary file, which can be used briefly.
|
|
193
101
|
* @param {string} fileContents contents which will be written to a temp file.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const { ObjectStore, makeSureBucketExists, upload, deleteFiles, streamUpload, retrieve, retrieveToTmp, deleteFolder, uploadDirectory, downloadTarball, downloadTarballDirect, } = require("@budibase/backend-core/objectStore");
|
|
2
|
+
const { ObjectStore, makeSureBucketExists, upload, deleteFiles, streamUpload, retrieve, retrieveToTmp, retrieveDirectory, deleteFolder, uploadDirectory, downloadTarball, downloadTarballDirect, } = require("@budibase/backend-core/objectStore");
|
|
3
3
|
/***********************************
|
|
4
4
|
* NOTE *
|
|
5
5
|
* This file purely exists so that *
|
|
@@ -14,6 +14,7 @@ exports.upload = upload;
|
|
|
14
14
|
exports.streamUpload = streamUpload;
|
|
15
15
|
exports.retrieve = retrieve;
|
|
16
16
|
exports.retrieveToTmp = retrieveToTmp;
|
|
17
|
+
exports.retrieveDirectory = retrieveDirectory;
|
|
17
18
|
exports.deleteFolder = deleteFolder;
|
|
18
19
|
exports.uploadDirectory = uploadDirectory;
|
|
19
20
|
exports.downloadTarball = downloadTarball;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.0.30-alpha.
|
|
4
|
+
"version": "2.0.30-alpha.16",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -77,23 +77,23 @@
|
|
|
77
77
|
"license": "GPL-3.0",
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@apidevtools/swagger-parser": "10.0.3",
|
|
80
|
-
"@budibase/backend-core": "2.0.30-alpha.
|
|
81
|
-
"@budibase/client": "2.0.30-alpha.
|
|
82
|
-
"@budibase/pro": "2.0.30-alpha.
|
|
83
|
-
"@budibase/string-templates": "2.0.30-alpha.
|
|
84
|
-
"@budibase/types": "2.0.30-alpha.
|
|
80
|
+
"@budibase/backend-core": "2.0.30-alpha.16",
|
|
81
|
+
"@budibase/client": "2.0.30-alpha.16",
|
|
82
|
+
"@budibase/pro": "2.0.30-alpha.15",
|
|
83
|
+
"@budibase/string-templates": "2.0.30-alpha.16",
|
|
84
|
+
"@budibase/types": "2.0.30-alpha.16",
|
|
85
85
|
"@bull-board/api": "3.7.0",
|
|
86
86
|
"@bull-board/koa": "3.9.4",
|
|
87
87
|
"@elastic/elasticsearch": "7.10.0",
|
|
88
88
|
"@google-cloud/firestore": "5.0.2",
|
|
89
|
-
"@koa/router": "8.0.
|
|
89
|
+
"@koa/router": "8.0.8",
|
|
90
90
|
"@sendgrid/mail": "7.1.1",
|
|
91
91
|
"@sentry/node": "6.17.7",
|
|
92
92
|
"airtable": "0.10.1",
|
|
93
93
|
"arangojs": "7.2.0",
|
|
94
94
|
"aws-sdk": "2.1030.0",
|
|
95
95
|
"bcryptjs": "2.4.3",
|
|
96
|
-
"bull": "4.
|
|
96
|
+
"bull": "4.10.1",
|
|
97
97
|
"chmodr": "1.2.0",
|
|
98
98
|
"chokidar": "3.5.3",
|
|
99
99
|
"csvtojson": "2.0.10",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"js-yaml": "4.1.0",
|
|
113
113
|
"jsonschema": "1.4.0",
|
|
114
114
|
"knex": "0.95.15",
|
|
115
|
-
"koa": "2.
|
|
115
|
+
"koa": "2.13.4",
|
|
116
116
|
"koa-body": "4.2.0",
|
|
117
117
|
"koa-compress": "4.0.1",
|
|
118
118
|
"koa-connect": "2.1.0",
|
|
@@ -159,12 +159,12 @@
|
|
|
159
159
|
"@jest/test-sequencer": "24.9.0",
|
|
160
160
|
"@types/apidoc": "0.50.0",
|
|
161
161
|
"@types/bson": "4.2.0",
|
|
162
|
-
"@types/bull": "3.15.8",
|
|
163
162
|
"@types/global-agent": "2.1.1",
|
|
164
163
|
"@types/google-spreadsheet": "3.1.5",
|
|
164
|
+
"@types/ioredis": "4.28.10",
|
|
165
165
|
"@types/jest": "27.5.1",
|
|
166
166
|
"@types/koa": "2.13.4",
|
|
167
|
-
"@types/koa__router": "8.0.
|
|
167
|
+
"@types/koa__router": "8.0.11",
|
|
168
168
|
"@types/lodash": "4.14.180",
|
|
169
169
|
"@types/node": "14.18.20",
|
|
170
170
|
"@types/node-fetch": "2.6.1",
|
|
@@ -198,5 +198,5 @@
|
|
|
198
198
|
"optionalDependencies": {
|
|
199
199
|
"oracledb": "5.3.0"
|
|
200
200
|
},
|
|
201
|
-
"gitHead": "
|
|
201
|
+
"gitHead": "ee82e064777bff81542e7e8a1954f0deb4992a9f"
|
|
202
202
|
}
|
|
@@ -5,11 +5,7 @@ import {
|
|
|
5
5
|
createRoutingView,
|
|
6
6
|
createAllSearchIndex,
|
|
7
7
|
} from "../../db/views/staticViews"
|
|
8
|
-
import {
|
|
9
|
-
getTemplateStream,
|
|
10
|
-
createApp,
|
|
11
|
-
deleteApp,
|
|
12
|
-
} from "../../utilities/fileSystem"
|
|
8
|
+
import { createApp, deleteApp } from "../../utilities/fileSystem"
|
|
13
9
|
import {
|
|
14
10
|
generateAppID,
|
|
15
11
|
getLayoutParams,
|
|
@@ -50,6 +46,7 @@ import { errors, events, migrations } from "@budibase/backend-core"
|
|
|
50
46
|
import { App, Layout, Screen, MigrationType } from "@budibase/types"
|
|
51
47
|
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
|
52
48
|
import { enrichPluginURLs } from "../../utilities/plugins"
|
|
49
|
+
import sdk from "../../sdk"
|
|
53
50
|
|
|
54
51
|
const URL_REGEX_SLASH = /\/|\\/g
|
|
55
52
|
|
|
@@ -153,11 +150,7 @@ async function createInstance(template: any) {
|
|
|
153
150
|
throw "Error loading database dump from memory."
|
|
154
151
|
}
|
|
155
152
|
} else if (template && template.useTemplate === "true") {
|
|
156
|
-
|
|
157
|
-
const { ok } = await db.load(await getTemplateStream(template))
|
|
158
|
-
if (!ok) {
|
|
159
|
-
throw "Error loading database dump from template."
|
|
160
|
-
}
|
|
153
|
+
await sdk.backups.importApp(appId, db, template)
|
|
161
154
|
} else {
|
|
162
155
|
// create the users table
|
|
163
156
|
await db.put(USERS_TABLE_SCHEMA)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import sdk from "../../sdk"
|
|
2
|
+
import { events, context } from "@budibase/backend-core"
|
|
3
|
+
import { DocumentType } from "../../db/utils"
|
|
4
|
+
import { isQsTrue } from "../../utilities"
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export async function exportAppDump(ctx: any) {
|
|
7
7
|
let { appId, excludeRows } = ctx.query
|
|
8
8
|
const appName = decodeURI(ctx.query.appname)
|
|
9
9
|
excludeRows = isQsTrue(excludeRows)
|
|
10
|
-
const backupIdentifier = `${appName}-export-${new Date().getTime()}.
|
|
10
|
+
const backupIdentifier = `${appName}-export-${new Date().getTime()}.tar.gz`
|
|
11
11
|
ctx.attachment(backupIdentifier)
|
|
12
|
-
ctx.body = await
|
|
12
|
+
ctx.body = await sdk.backups.streamExportApp(appId, excludeRows)
|
|
13
13
|
|
|
14
14
|
await context.doInAppContext(appId, async () => {
|
|
15
15
|
const appDb = context.getAppDB()
|
|
@@ -1,58 +1,59 @@
|
|
|
1
1
|
const env = require("../../environment")
|
|
2
2
|
const { getAllApps, getGlobalDBName } = require("@budibase/backend-core/db")
|
|
3
|
-
const {
|
|
4
|
-
exportDB,
|
|
5
|
-
sendTempFile,
|
|
6
|
-
readFileSync,
|
|
7
|
-
} = require("../../utilities/fileSystem")
|
|
8
|
-
const { stringToReadStream } = require("../../utilities")
|
|
9
3
|
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
10
|
-
const {
|
|
4
|
+
const { streamFile } = require("../../utilities/fileSystem")
|
|
5
|
+
const { stringToReadStream } = require("../../utilities")
|
|
11
6
|
const { getDocParams, DocumentType, isDevAppID } = require("../../db/utils")
|
|
7
|
+
const { create } = require("./application")
|
|
8
|
+
const { join } = require("path")
|
|
9
|
+
const sdk = require("../../sdk")
|
|
12
10
|
|
|
13
|
-
async function createApp(appName,
|
|
11
|
+
async function createApp(appName, appDirectory) {
|
|
14
12
|
const ctx = {
|
|
15
13
|
request: {
|
|
16
14
|
body: {
|
|
17
|
-
|
|
15
|
+
useTemplate: true,
|
|
18
16
|
name: appName,
|
|
19
17
|
},
|
|
18
|
+
files: {
|
|
19
|
+
templateFile: {
|
|
20
|
+
path: appDirectory,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
20
23
|
},
|
|
21
24
|
}
|
|
22
25
|
return create(ctx)
|
|
23
26
|
}
|
|
24
27
|
|
|
28
|
+
async function getAllDocType(db, docType) {
|
|
29
|
+
const response = await db.allDocs(
|
|
30
|
+
getDocParams(docType, null, {
|
|
31
|
+
include_docs: true,
|
|
32
|
+
})
|
|
33
|
+
)
|
|
34
|
+
return response.rows.map(row => row.doc)
|
|
35
|
+
}
|
|
36
|
+
|
|
25
37
|
exports.exportApps = async ctx => {
|
|
26
38
|
if (env.SELF_HOSTED || !env.MULTI_TENANCY) {
|
|
27
39
|
ctx.throw(400, "Exporting only allowed in multi-tenant cloud environments.")
|
|
28
40
|
}
|
|
29
41
|
const apps = await getAllApps({ all: true })
|
|
30
|
-
const globalDBString = await exportDB(getGlobalDBName(), {
|
|
42
|
+
const globalDBString = await sdk.backups.exportDB(getGlobalDBName(), {
|
|
31
43
|
filter: doc => !doc._id.startsWith(DocumentType.USER),
|
|
32
44
|
})
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
allDBs[app.name] = await exportDB(appId)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const filename = `cloud-export-${new Date().getTime()}.txt`
|
|
45
|
-
ctx.attachment(filename)
|
|
46
|
-
ctx.body = sendTempFile(JSON.stringify(allDBs))
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function getAllDocType(db, docType) {
|
|
50
|
-
const response = await db.allDocs(
|
|
51
|
-
getDocParams(docType, null, {
|
|
52
|
-
include_docs: true,
|
|
53
|
-
})
|
|
45
|
+
// only export the dev apps as they will be the latest, the user can republish the apps
|
|
46
|
+
// in their self-hosted environment
|
|
47
|
+
let appMetadata = apps
|
|
48
|
+
.filter(app => isDevAppID(app.appId || app._id))
|
|
49
|
+
.map(app => ({ appId: app.appId || app._id, name: app.name }))
|
|
50
|
+
const tmpPath = await sdk.backups.exportMultipleApps(
|
|
51
|
+
appMetadata,
|
|
52
|
+
globalDBString
|
|
54
53
|
)
|
|
55
|
-
|
|
54
|
+
const filename = `cloud-export-${new Date().getTime()}.tar.gz`
|
|
55
|
+
ctx.attachment(filename)
|
|
56
|
+
ctx.body = streamFile(tmpPath)
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
async function hasBeenImported() {
|
|
@@ -80,17 +81,20 @@ exports.importApps = async ctx => {
|
|
|
80
81
|
"Import file is required and environment must be fresh to import apps."
|
|
81
82
|
)
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
//
|
|
88
|
-
|
|
84
|
+
if (ctx.request.files.importFile.type !== "application/gzip") {
|
|
85
|
+
ctx.throw(400, "Import file must be a gzipped tarball.")
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// initially get all the app databases out of the tarball
|
|
89
|
+
const tmpPath = sdk.backups.untarFile(ctx.request.files.importFile)
|
|
90
|
+
const globalDbImport = sdk.backups.getGlobalDBFile(tmpPath)
|
|
91
|
+
const appNames = sdk.backups.getListOfAppsInMulti(tmpPath)
|
|
92
|
+
|
|
89
93
|
const globalDb = getGlobalDB()
|
|
90
94
|
// load the global db first
|
|
91
95
|
await globalDb.load(stringToReadStream(globalDbImport))
|
|
92
|
-
for (let
|
|
93
|
-
await createApp(appName,
|
|
96
|
+
for (let appName of appNames) {
|
|
97
|
+
await createApp(appName, join(tmpPath, appName))
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
// if there are any users make sure to remove them
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import Deployment from "./Deployment"
|
|
2
2
|
import {
|
|
3
|
-
Replication,
|
|
4
|
-
getProdAppID,
|
|
5
3
|
getDevelopmentAppID,
|
|
4
|
+
getProdAppID,
|
|
5
|
+
Replication,
|
|
6
6
|
} from "@budibase/backend-core/db"
|
|
7
7
|
import { DocumentType, getAutomationParams } from "../../../db/utils"
|
|
8
8
|
import {
|
|
9
|
+
clearMetadata,
|
|
9
10
|
disableAllCrons,
|
|
10
11
|
enableCronTrigger,
|
|
11
|
-
clearMetadata,
|
|
12
12
|
} from "../../../automations/utils"
|
|
13
13
|
import { app as appCache } from "@budibase/backend-core/cache"
|
|
14
14
|
import {
|
|
15
|
-
getAppId,
|
|
16
15
|
getAppDB,
|
|
17
|
-
|
|
16
|
+
getAppId,
|
|
18
17
|
getDevAppDB,
|
|
18
|
+
getProdAppDB,
|
|
19
19
|
} from "@budibase/backend-core/context"
|
|
20
20
|
import { events } from "@budibase/backend-core"
|
|
21
|
+
import { backups } from "@budibase/pro"
|
|
22
|
+
import { AppBackupTrigger } from "@budibase/types"
|
|
21
23
|
|
|
22
24
|
// the max time we can wait for an invalidation to complete before considering it failed
|
|
23
25
|
const MAX_PENDING_TIME_MS = 30 * 60000
|
|
@@ -98,13 +100,24 @@ async function initDeployedApp(prodAppId: any) {
|
|
|
98
100
|
console.log("Enabled cron triggers for deployed app..")
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
async function deployApp(deployment: any) {
|
|
103
|
+
async function deployApp(deployment: any, userId: string) {
|
|
102
104
|
let replication
|
|
103
105
|
try {
|
|
104
106
|
const appId = getAppId()
|
|
105
107
|
const devAppId = getDevelopmentAppID(appId)
|
|
106
108
|
const productionAppId = getProdAppID(appId)
|
|
107
109
|
|
|
110
|
+
// don't try this if feature isn't allowed, will error
|
|
111
|
+
if (await backups.isEnabled()) {
|
|
112
|
+
// trigger backup initially
|
|
113
|
+
await backups.triggerAppBackup(
|
|
114
|
+
productionAppId,
|
|
115
|
+
AppBackupTrigger.PUBLISH,
|
|
116
|
+
{
|
|
117
|
+
createdBy: userId,
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
}
|
|
108
121
|
const config: any = {
|
|
109
122
|
source: devAppId,
|
|
110
123
|
target: productionAppId,
|
|
@@ -205,7 +218,7 @@ const _deployApp = async function (ctx: any) {
|
|
|
205
218
|
|
|
206
219
|
console.log("Deploying app...")
|
|
207
220
|
|
|
208
|
-
let app = await deployApp(deployment)
|
|
221
|
+
let app = await deployApp(deployment, ctx.user._id)
|
|
209
222
|
|
|
210
223
|
await events.app.published(app)
|
|
211
224
|
ctx.body = deployment
|
|
@@ -5,7 +5,7 @@ require("svelte/register")
|
|
|
5
5
|
const send = require("koa-send")
|
|
6
6
|
const { resolve, join } = require("../../../utilities/centralPath")
|
|
7
7
|
const uuid = require("uuid")
|
|
8
|
-
const { ObjectStoreBuckets } = require("../../../constants")
|
|
8
|
+
const { ObjectStoreBuckets, ATTACHMENT_DIR } = require("../../../constants")
|
|
9
9
|
const { processString } = require("@budibase/string-templates")
|
|
10
10
|
const {
|
|
11
11
|
loadHandlebarsFile,
|
|
@@ -90,7 +90,7 @@ export const uploadFile = async function (ctx: any) {
|
|
|
90
90
|
|
|
91
91
|
return prepareUpload({
|
|
92
92
|
file,
|
|
93
|
-
s3Key: `${ctx.appId}
|
|
93
|
+
s3Key: `${ctx.appId}/${ATTACHMENT_DIR}/${processedFileName}`,
|
|
94
94
|
bucket: ObjectStoreBuckets.APPS,
|
|
95
95
|
})
|
|
96
96
|
})
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const { FieldTypes, FormulaTypes } = require("../../../constants")
|
|
2
|
-
const {
|
|
2
|
+
const { clearColumns } = require("./utils")
|
|
3
3
|
const { doesContainStrings } = require("@budibase/string-templates")
|
|
4
4
|
const { cloneDeep } = require("lodash/fp")
|
|
5
5
|
const { isEqual, uniq } = require("lodash")
|
|
6
6
|
const { updateAllFormulasInTable } = require("../row/staticFormula")
|
|
7
7
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
8
|
+
const sdk = require("../../../sdk")
|
|
8
9
|
|
|
9
10
|
function isStaticFormula(column) {
|
|
10
11
|
return (
|
|
@@ -39,7 +40,7 @@ function getFormulaThatUseColumn(table, columnNames) {
|
|
|
39
40
|
*/
|
|
40
41
|
async function checkIfFormulaNeedsCleared(table, { oldTable, deletion }) {
|
|
41
42
|
// start by retrieving all tables, remove the current table from the list
|
|
42
|
-
const tables = (await getAllInternalTables()).filter(
|
|
43
|
+
const tables = (await sdk.tables.getAllInternalTables()).filter(
|
|
43
44
|
tbl => tbl._id !== table._id
|
|
44
45
|
)
|
|
45
46
|
const schemaToUse = oldTable ? oldTable.schema : table.schema
|
|
@@ -99,7 +100,7 @@ async function updateRelatedFormulaLinksOnTables(
|
|
|
99
100
|
) {
|
|
100
101
|
const db = getAppDB()
|
|
101
102
|
// start by retrieving all tables, remove the current table from the list
|
|
102
|
-
const tables = (await getAllInternalTables()).filter(
|
|
103
|
+
const tables = (await sdk.tables.getAllInternalTables()).filter(
|
|
103
104
|
tbl => tbl._id !== table._id
|
|
104
105
|
)
|
|
105
106
|
// clone the tables, so we can compare at end
|
|
@@ -3,7 +3,6 @@ const {
|
|
|
3
3
|
breakExternalTableId,
|
|
4
4
|
} = require("../../../integrations/utils")
|
|
5
5
|
const {
|
|
6
|
-
getTable,
|
|
7
6
|
generateForeignKey,
|
|
8
7
|
generateJunctionTableName,
|
|
9
8
|
foreignKeyStructure,
|
|
@@ -20,6 +19,7 @@ const csvParser = require("../../../utilities/csvParser")
|
|
|
20
19
|
const { handleRequest } = require("../row/external")
|
|
21
20
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
22
21
|
const { events } = require("@budibase/backend-core")
|
|
22
|
+
const sdk = require("../../../sdk")
|
|
23
23
|
|
|
24
24
|
async function makeTableRequest(
|
|
25
25
|
datasource,
|
|
@@ -181,7 +181,7 @@ exports.save = async function (ctx) {
|
|
|
181
181
|
|
|
182
182
|
let oldTable
|
|
183
183
|
if (ctx.request.body && ctx.request.body._id) {
|
|
184
|
-
oldTable = await getTable(ctx.request.body._id)
|
|
184
|
+
oldTable = await sdk.tables.getTable(ctx.request.body._id)
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
if (hasTypeChanged(tableToSave, oldTable)) {
|
|
@@ -281,7 +281,7 @@ exports.save = async function (ctx) {
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
exports.destroy = async function (ctx) {
|
|
284
|
-
const tableToDelete = await getTable(ctx.params.tableId)
|
|
284
|
+
const tableToDelete = await sdk.tables.getTable(ctx.params.tableId)
|
|
285
285
|
if (!tableToDelete || !tableToDelete.created) {
|
|
286
286
|
ctx.throw(400, "Cannot delete tables which weren't created in Budibase.")
|
|
287
287
|
}
|
|
@@ -303,7 +303,7 @@ exports.destroy = async function (ctx) {
|
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
exports.bulkImport = async function (ctx) {
|
|
306
|
-
const table = await getTable(ctx.params.tableId)
|
|
306
|
+
const table = await sdk.tables.getTable(ctx.params.tableId)
|
|
307
307
|
const { dataImport } = ctx.request.body
|
|
308
308
|
if (!dataImport || !dataImport.schema || !dataImport.csvString) {
|
|
309
309
|
ctx.throw(400, "Provided data import information is invalid.")
|
|
@@ -4,8 +4,8 @@ const csvParser = require("../../../utilities/csvParser")
|
|
|
4
4
|
const { isExternalTable, isSQL } = require("../../../integrations/utils")
|
|
5
5
|
const { getDatasourceParams } = require("../../../db/utils")
|
|
6
6
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
7
|
-
const { getTable, getAllInternalTables } = require("./utils")
|
|
8
7
|
const { events } = require("@budibase/backend-core")
|
|
8
|
+
const sdk = require("../../../sdk")
|
|
9
9
|
|
|
10
10
|
function pickApi({ tableId, table }) {
|
|
11
11
|
if (table && !tableId) {
|
|
@@ -23,7 +23,7 @@ function pickApi({ tableId, table }) {
|
|
|
23
23
|
exports.fetch = async function (ctx) {
|
|
24
24
|
const db = getAppDB()
|
|
25
25
|
|
|
26
|
-
const internal = await getAllInternalTables()
|
|
26
|
+
const internal = await sdk.tables.getAllInternalTables()
|
|
27
27
|
|
|
28
28
|
const externalTables = await db.allDocs(
|
|
29
29
|
getDatasourceParams("plus", {
|
|
@@ -50,7 +50,7 @@ exports.fetch = async function (ctx) {
|
|
|
50
50
|
|
|
51
51
|
exports.find = async function (ctx) {
|
|
52
52
|
const tableId = ctx.params.tableId
|
|
53
|
-
ctx.body = await getTable(tableId)
|
|
53
|
+
ctx.body = await sdk.tables.getTable(tableId)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
exports.save = async function (ctx) {
|
|
@@ -101,7 +101,7 @@ exports.validateCSVSchema = async function (ctx) {
|
|
|
101
101
|
const { csvString, schema = {}, tableId } = ctx.request.body
|
|
102
102
|
let existingTable
|
|
103
103
|
if (tableId) {
|
|
104
|
-
existingTable = await getTable(tableId)
|
|
104
|
+
existingTable = await sdk.tables.getTable(tableId)
|
|
105
105
|
}
|
|
106
106
|
let result = await csvParser.parse(csvString, schema)
|
|
107
107
|
if (existingTable) {
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { updateLinks, EventType } from "../../../db/linkedRows"
|
|
2
2
|
import { getRowParams, generateTableID } from "../../../db/utils"
|
|
3
3
|
import { FieldTypes } from "../../../constants"
|
|
4
|
-
import {
|
|
5
|
-
TableSaveFunctions,
|
|
6
|
-
hasTypeChanged,
|
|
7
|
-
getTable,
|
|
8
|
-
handleDataImport,
|
|
9
|
-
} from "./utils"
|
|
4
|
+
import { TableSaveFunctions, hasTypeChanged, handleDataImport } from "./utils"
|
|
10
5
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
11
6
|
import { isTest } from "../../../environment"
|
|
12
7
|
import {
|
|
@@ -19,6 +14,7 @@ import { quotas } from "@budibase/pro"
|
|
|
19
14
|
import { isEqual } from "lodash"
|
|
20
15
|
import { cloneDeep } from "lodash/fp"
|
|
21
16
|
import env from "../../../environment"
|
|
17
|
+
import sdk from "../../../sdk"
|
|
22
18
|
|
|
23
19
|
function checkAutoColumns(table: Table, oldTable: Table) {
|
|
24
20
|
if (!table.schema) {
|
|
@@ -188,7 +184,7 @@ export async function destroy(ctx: any) {
|
|
|
188
184
|
}
|
|
189
185
|
|
|
190
186
|
export async function bulkImport(ctx: any) {
|
|
191
|
-
const table = await getTable(ctx.params.tableId)
|
|
187
|
+
const table = await sdk.tables.getTable(ctx.params.tableId)
|
|
192
188
|
const { dataImport } = ctx.request.body
|
|
193
189
|
await handleDataImport(ctx.user, table, dataImport)
|
|
194
190
|
return table
|