@budibase/server 1.0.49-alpha.0 → 1.0.49-alpha.4

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.
Files changed (239) hide show
  1. package/builder/assets/{index.dd9e386f.css → index.83c0944f.css} +1 -1
  2. package/builder/assets/{index.8184eed9.js → index.f763d886.js} +206 -205
  3. package/builder/assets/{vendor.3bd2f661.js → vendor.d526bfe8.js} +1 -1
  4. package/builder/index.html +3 -3
  5. package/coverage/clover.xml +1743 -1610
  6. package/coverage/coverage-final.json +90 -89
  7. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/application.js.html +106 -106
  10. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
  12. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
  16. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/index.html +27 -12
  18. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
  20. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  21. package/coverage/lcov-report/{migrations/usageQuotas/syncApps.js.html → api/controllers/migrations.js.html} +30 -45
  22. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  23. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/query/index.js.html +19 -19
  25. package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
  26. package/coverage/lcov-report/api/controllers/role.js.html +9 -9
  27. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
  29. package/coverage/lcov-report/api/controllers/row/index.html +40 -25
  30. package/coverage/lcov-report/api/controllers/row/index.js.html +13 -13
  31. package/coverage/lcov-report/api/controllers/row/internal.js.html +83 -146
  32. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +41 -17
  33. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +551 -0
  34. package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
  35. package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
  36. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  37. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +629 -0
  38. package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
  39. package/coverage/lcov-report/api/controllers/table/index.html +45 -30
  40. package/coverage/lcov-report/api/controllers/table/index.js.html +23 -65
  41. package/coverage/lcov-report/api/controllers/table/internal.js.html +33 -15
  42. package/coverage/lcov-report/api/controllers/table/utils.js.html +161 -41
  43. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/user.js.html +20 -20
  45. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  46. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  47. package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
  48. package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
  49. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  50. package/coverage/lcov-report/api/controllers/webhook.js.html +15 -15
  51. package/coverage/lcov-report/api/index.html +1 -1
  52. package/coverage/lcov-report/api/index.js.html +3 -3
  53. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/index.html +22 -7
  65. package/coverage/lcov-report/api/routes/index.js.html +10 -4
  66. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  69. package/coverage/lcov-report/{migrations/usageQuotas/index.js.html → api/routes/migrations.js.html} +25 -55
  70. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  80. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  82. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  83. package/coverage/lcov-report/automations/actions.js.html +24 -24
  84. package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
  85. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  86. package/coverage/lcov-report/automations/index.html +1 -1
  87. package/coverage/lcov-report/automations/index.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  89. package/coverage/lcov-report/automations/steps/createRow.js.html +7 -7
  90. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  91. package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
  92. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  93. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  94. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  95. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  96. package/coverage/lcov-report/automations/steps/index.html +1 -1
  97. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  98. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  99. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  100. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  101. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  102. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  103. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  104. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  105. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  106. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  107. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  108. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  109. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  110. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  111. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  112. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  113. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  114. package/coverage/lcov-report/automations/triggers.js.html +18 -18
  115. package/coverage/lcov-report/automations/utils.js.html +32 -32
  116. package/coverage/lcov-report/constants/index.html +5 -5
  117. package/coverage/lcov-report/constants/index.js.html +42 -27
  118. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  119. package/coverage/lcov-report/constants/screens.js.html +4 -4
  120. package/coverage/lcov-report/db/client.js.html +18 -18
  121. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  122. package/coverage/lcov-report/db/index.html +1 -1
  123. package/coverage/lcov-report/db/index.js.html +3 -3
  124. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +7 -7
  125. package/coverage/lcov-report/db/linkedRows/index.html +10 -10
  126. package/coverage/lcov-report/db/linkedRows/index.js.html +26 -29
  127. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +13 -13
  128. package/coverage/lcov-report/db/newid.js.html +4 -4
  129. package/coverage/lcov-report/db/utils.js.html +71 -71
  130. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  131. package/coverage/lcov-report/events/index.html +1 -1
  132. package/coverage/lcov-report/events/index.js.html +5 -5
  133. package/coverage/lcov-report/events/utils.js.html +3 -3
  134. package/coverage/lcov-report/index.html +61 -76
  135. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  136. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  137. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  138. package/coverage/lcov-report/middleware/authorized.js.html +1 -1
  139. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  140. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  141. package/coverage/lcov-report/middleware/index.html +11 -11
  142. package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
  143. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  144. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  145. package/coverage/lcov-report/middleware/usageQuota.js.html +6 -12
  146. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  147. package/coverage/lcov-report/threads/automation.js.html +1 -1
  148. package/coverage/lcov-report/threads/index.html +1 -1
  149. package/coverage/lcov-report/threads/index.js.html +10 -10
  150. package/coverage/lcov-report/threads/query.js.html +1 -1
  151. package/coverage/lcov-report/threads/utils.js.html +14 -14
  152. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  153. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  154. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  155. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  156. package/coverage/lcov-report/utilities/global.js.html +14 -14
  157. package/coverage/lcov-report/utilities/index.html +1 -1
  158. package/coverage/lcov-report/utilities/index.js.html +24 -24
  159. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
  160. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  161. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  162. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  163. package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
  164. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +80 -44
  165. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +75 -27
  166. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  167. package/coverage/lcov-report/utilities/security.js.html +8 -8
  168. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  169. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  170. package/coverage/lcov-report/utilities/usageQuota/index.js.html +10 -10
  171. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  172. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  173. package/coverage/lcov-report/utilities/users.js.html +5 -5
  174. package/coverage/lcov-report/utilities/workerRequests.js.html +12 -12
  175. package/coverage/lcov.info +2545 -2257
  176. package/dist/api/controllers/application.js +18 -20
  177. package/dist/api/controllers/migrations.js +21 -0
  178. package/dist/api/controllers/row/internal.js +30 -53
  179. package/dist/api/controllers/row/internalSearch.js +12 -4
  180. package/dist/api/controllers/row/staticFormula.js +147 -0
  181. package/dist/api/controllers/table/bulkFormula.js +160 -0
  182. package/dist/api/controllers/table/index.js +3 -6
  183. package/dist/api/controllers/table/internal.js +7 -0
  184. package/dist/api/controllers/table/utils.js +32 -10
  185. package/dist/api/routes/index.js +2 -0
  186. package/dist/api/routes/migrations.js +9 -0
  187. package/dist/app.js +35 -5
  188. package/dist/constants/index.js +4 -0
  189. package/dist/db/linkedRows/index.js +4 -5
  190. package/dist/environment.js +1 -0
  191. package/dist/middleware/usageQuota.js +0 -2
  192. package/dist/migrations/functions/appUrls.js +46 -0
  193. package/dist/migrations/functions/quotas1.js +50 -0
  194. package/dist/migrations/{usageQuotas → functions/usageQuotas}/index.js +6 -10
  195. package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncApps.js +11 -5
  196. package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncRows.js +14 -8
  197. package/dist/migrations/functions/userEmailViewCasing.js +24 -0
  198. package/dist/migrations/index.js +62 -0
  199. package/dist/package.json +4 -4
  200. package/dist/tests/utilities/TestConfiguration.js +3 -0
  201. package/dist/tsconfig.tsbuildinfo +1 -1
  202. package/dist/utilities/rowProcessor/index.js +18 -11
  203. package/dist/utilities/rowProcessor/utils.js +14 -4
  204. package/package.json +5 -5
  205. package/src/api/controllers/application.js +3 -3
  206. package/src/api/controllers/migrations.js +13 -0
  207. package/src/api/controllers/row/internal.js +29 -50
  208. package/src/api/controllers/row/internalSearch.js +12 -4
  209. package/src/api/controllers/row/staticFormula.js +157 -0
  210. package/src/api/controllers/table/bulkFormula.js +183 -0
  211. package/src/api/controllers/table/index.js +3 -17
  212. package/src/api/controllers/table/internal.js +7 -1
  213. package/src/api/controllers/table/utils.js +48 -8
  214. package/src/api/routes/index.js +2 -0
  215. package/src/api/routes/migrations.js +14 -0
  216. package/src/app.ts +18 -5
  217. package/src/constants/index.js +5 -0
  218. package/src/db/linkedRows/index.js +4 -5
  219. package/src/definitions/common.ts +3 -0
  220. package/src/environment.js +1 -0
  221. package/src/middleware/usageQuota.js +0 -2
  222. package/src/migrations/functions/appUrls.ts +34 -0
  223. package/src/migrations/functions/quotas1.ts +20 -0
  224. package/src/migrations/functions/tests/appUrls.spec.js +29 -0
  225. package/src/migrations/{tests/usageQuotas/index.spec.js → functions/tests/quotas1.spec.js} +5 -5
  226. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +25 -0
  227. package/src/migrations/functions/usageQuotas/index.ts +8 -0
  228. package/src/migrations/{usageQuotas/syncApps.js → functions/usageQuotas/syncApps.ts} +3 -3
  229. package/src/migrations/{usageQuotas/syncRows.js → functions/usageQuotas/syncRows.ts} +5 -5
  230. package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncApps.spec.js +4 -4
  231. package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncRows.spec.js +4 -4
  232. package/src/migrations/functions/userEmailViewCasing.ts +13 -0
  233. package/src/migrations/index.ts +56 -0
  234. package/src/tests/utilities/TestConfiguration.js +4 -0
  235. package/src/utilities/rowProcessor/index.js +24 -12
  236. package/src/utilities/rowProcessor/utils.js +23 -7
  237. package/coverage/lcov-report/migrations/usageQuotas/index.html +0 -141
  238. package/coverage/lcov-report/migrations/usageQuotas/syncRows.js.html +0 -143
  239. package/src/migrations/usageQuotas/index.js +0 -24
@@ -10,16 +10,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  const CouchDB = require("../../../db");
12
12
  const csvParser = require("../../../utilities/csvParser");
13
- const { getRowParams, generateRowID, InternalTables, } = require("../../../db/utils");
14
- const { isEqual } = require("lodash/fp");
13
+ const { getRowParams, generateRowID, InternalTables, getTableParams, BudibaseInternalDB, } = require("../../../db/utils");
14
+ const { isEqual } = require("lodash");
15
15
  const { AutoFieldSubTypes, FieldTypes } = require("../../../constants");
16
- const { inputProcessing } = require("../../../utilities/rowProcessor");
16
+ const { inputProcessing, cleanupAttachments, } = require("../../../utilities/rowProcessor");
17
17
  const { USERS_TABLE_SCHEMA, SwitchableTypes, CanSwitchTypes, } = require("../../../constants");
18
18
  const { isExternalTable, breakExternalTableId, isSQL, } = require("../../../integrations/utils");
19
19
  const { getViews, saveView } = require("../view/utils");
20
20
  const viewTemplate = require("../view/viewBuilder");
21
21
  const usageQuota = require("../../../utilities/usageQuota");
22
- exports.checkForColumnUpdates = (db, oldTable, updatedTable) => __awaiter(void 0, void 0, void 0, function* () {
22
+ const { cloneDeep } = require("lodash/fp");
23
+ exports.clearColumns = (appId, table, columnNames) => __awaiter(void 0, void 0, void 0, function* () {
24
+ const db = new CouchDB(appId);
25
+ const rows = yield db.allDocs(getRowParams(table._id, null, {
26
+ include_docs: true,
27
+ }));
28
+ return db.bulkDocs(rows.rows.map(({ doc }) => {
29
+ columnNames.forEach(colName => delete doc[colName]);
30
+ return doc;
31
+ }));
32
+ });
33
+ exports.checkForColumnUpdates = (appId, db, oldTable, updatedTable) => __awaiter(void 0, void 0, void 0, function* () {
23
34
  let updatedRows = [];
24
35
  const rename = updatedTable._rename;
25
36
  let deletedColumns = [];
@@ -32,16 +43,20 @@ exports.checkForColumnUpdates = (db, oldTable, updatedTable) => __awaiter(void 0
32
43
  const rows = yield db.allDocs(getRowParams(updatedTable._id, null, {
33
44
  include_docs: true,
34
45
  }));
35
- updatedRows = rows.rows.map(({ doc }) => {
46
+ const rawRows = rows.rows.map(({ doc }) => doc);
47
+ updatedRows = rawRows.map(row => {
48
+ row = cloneDeep(row);
36
49
  if (rename) {
37
- doc[rename.updated] = doc[rename.old];
38
- delete doc[rename.old];
50
+ row[rename.updated] = row[rename.old];
51
+ delete row[rename.old];
39
52
  }
40
53
  else if (deletedColumns.length !== 0) {
41
- deletedColumns.forEach(colName => delete doc[colName]);
54
+ deletedColumns.forEach(colName => delete row[colName]);
42
55
  }
43
- return doc;
56
+ return row;
44
57
  });
58
+ // cleanup any attachments from object storage for deleted attachment columns
59
+ yield cleanupAttachments(appId, updatedTable, { oldTable, rows: rawRows });
45
60
  // Update views
46
61
  yield exports.checkForViewUpdates(db, updatedTable, rename, deletedColumns);
47
62
  delete updatedTable._rename;
@@ -179,7 +194,7 @@ class TableSaveFunctions {
179
194
  // when confirmed valid
180
195
  mid(table) {
181
196
  return __awaiter(this, void 0, void 0, function* () {
182
- let response = yield exports.checkForColumnUpdates(this.db, this.oldTable, table);
197
+ let response = yield exports.checkForColumnUpdates(this.appId, this.db, this.oldTable, table);
183
198
  this.rows = this.rows.concat(response.rows);
184
199
  return table;
185
200
  });
@@ -196,6 +211,13 @@ class TableSaveFunctions {
196
211
  return this.rows;
197
212
  }
198
213
  }
214
+ exports.getAllInternalTables = (appId) => __awaiter(void 0, void 0, void 0, function* () {
215
+ const db = new CouchDB(appId);
216
+ const internalTables = yield db.allDocs(getTableParams(null, {
217
+ include_docs: true,
218
+ }));
219
+ return internalTables.rows.map(tableDoc => (Object.assign(Object.assign({}, tableDoc.doc), { type: "internal", sourceId: BudibaseInternalDB._id })));
220
+ });
199
221
  exports.getAllExternalTables = (appId, datasourceId) => __awaiter(void 0, void 0, void 0, function* () {
200
222
  const db = new CouchDB(appId);
201
223
  const datasource = yield db.get(datasourceId);
@@ -25,6 +25,7 @@ const backupRoutes = require("./backup");
25
25
  const metadataRoutes = require("./metadata");
26
26
  const devRoutes = require("./dev");
27
27
  const cloudRoutes = require("./cloud");
28
+ const migrationRoutes = require("./migrations");
28
29
  exports.mainRoutes = [
29
30
  authRoutes,
30
31
  deployRoutes,
@@ -53,5 +54,6 @@ exports.mainRoutes = [
53
54
  // this could be breaking as koa may recognise other routes as this
54
55
  tableRoutes,
55
56
  rowRoutes,
57
+ migrationRoutes,
56
58
  ];
57
59
  exports.staticRoutes = staticRoutes;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ const Router = require("@koa/router");
3
+ const migrationsController = require("../controllers/migrations");
4
+ const router = Router();
5
+ const { internalApi } = require("@budibase/backend-core/auth");
6
+ router
7
+ .post("/api/migrations/run", internalApi, migrationsController.migrate)
8
+ .get("/api/migrations/definitions", internalApi, migrationsController.fetchDefinitions);
9
+ module.exports = router;
package/dist/app.js CHANGED
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -9,7 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
28
  });
10
29
  };
11
30
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const env = require("./environment");
31
+ const env = __importStar(require("./environment"));
13
32
  const CouchDB = require("./db");
14
33
  require("@budibase/backend-core").init(CouchDB);
15
34
  const Koa = require("koa");
@@ -24,6 +43,7 @@ const Sentry = require("@sentry/node");
24
43
  const fileSystem = require("./utilities/fileSystem");
25
44
  const bullboard = require("./automations/bullboard");
26
45
  const redis = require("./utilities/redis");
46
+ const migrations = __importStar(require("./migrations"));
27
47
  const app = new Koa();
28
48
  // set up top level koa middleware
29
49
  app.use(koaBody({
@@ -76,12 +96,22 @@ module.exports = server.listen(env.PORT || 0, () => __awaiter(void 0, void 0, vo
76
96
  yield redis.init();
77
97
  yield automations.init();
78
98
  }));
79
- process.on("uncaughtException", err => {
80
- console.error(err);
99
+ const shutdown = () => {
81
100
  server.close();
82
101
  server.destroy();
102
+ };
103
+ process.on("uncaughtException", err => {
104
+ console.error(err);
105
+ shutdown();
83
106
  });
84
107
  process.on("SIGTERM", () => {
85
- server.close();
86
- server.destroy();
108
+ shutdown();
87
109
  });
110
+ // run migrations on startup if not done via http
111
+ // not recommended in a clustered environment
112
+ if (!env.HTTP_MIGRATIONS) {
113
+ migrations.migrate().catch(err => {
114
+ console.error("Error performing migrations. Exiting.\n", err);
115
+ shutdown();
116
+ });
117
+ }
@@ -52,6 +52,10 @@ exports.RelationshipTypes = {
52
52
  MANY_TO_ONE: "many-to-one",
53
53
  MANY_TO_MANY: "many-to-many",
54
54
  };
55
+ exports.FormulaTypes = {
56
+ STATIC: "static",
57
+ DYNAMIC: "dynamic",
58
+ };
55
59
  exports.AuthTypes = {
56
60
  APP: "app",
57
61
  BUILDER: "builder",
@@ -61,7 +61,7 @@ function getLinksForRows(appId, rows) {
61
61
  .map(el => (Object.assign(Object.assign({}, el), { unique: el.id + el.thisId + el.fieldName }))), "unique");
62
62
  });
63
63
  }
64
- function getFullLinkedDocs(ctx, appId, links) {
64
+ function getFullLinkedDocs(appId, links) {
65
65
  return __awaiter(this, void 0, void 0, function* () {
66
66
  // create DBs
67
67
  const db = new CouchDB(appId);
@@ -132,13 +132,12 @@ exports.updateLinks = function (args) {
132
132
  /**
133
133
  * Given a table and a list of rows this will retrieve all of the attached docs and enrich them into the row.
134
134
  * This is required for formula fields, this may only be utilised internally (for now).
135
- * @param {object} ctx The request which is looking for rows.
135
+ * @param {string} appId The ID of the app which this request is in the context of.
136
136
  * @param {object} table The table from which the rows originated.
137
137
  * @param {array<object>} rows The rows which are to be enriched.
138
138
  * @return {Promise<*>} returns the rows with all of the enriched relationships on it.
139
139
  */
140
- exports.attachFullLinkedDocs = (ctx, table, rows) => __awaiter(void 0, void 0, void 0, function* () {
141
- const appId = ctx.appId;
140
+ exports.attachFullLinkedDocs = (appId, table, rows) => __awaiter(void 0, void 0, void 0, function* () {
142
141
  const linkedTableIds = getLinkedTableIDs(table);
143
142
  if (linkedTableIds.length === 0) {
144
143
  return rows;
@@ -150,7 +149,7 @@ exports.attachFullLinkedDocs = (ctx, table, rows) => __awaiter(void 0, void 0, v
150
149
  // clear any existing links that could be dupe'd
151
150
  rows = clearRelationshipFields(table, rows);
152
151
  // now get the docs and combine into the rows
153
- let linked = yield getFullLinkedDocs(ctx, appId, links);
152
+ let linked = yield getFullLinkedDocs(appId, links);
154
153
  const linkedTables = [];
155
154
  for (let row of rows) {
156
155
  for (let link of links.filter(link => link.thisId === row._id)) {
@@ -35,6 +35,7 @@ module.exports = {
35
35
  REDIS_PASSWORD: process.env.REDIS_PASSWORD,
36
36
  INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
37
37
  MULTI_TENANCY: process.env.MULTI_TENANCY,
38
+ HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
38
39
  // environment
39
40
  NODE_ENV: process.env.NODE_ENV,
40
41
  JEST_WORKER_ID: process.env.JEST_WORKER_ID,
@@ -12,7 +12,6 @@ const CouchDB = require("../db");
12
12
  const usageQuota = require("../utilities/usageQuota");
13
13
  const { getUniqueRows } = require("../utilities/usageQuota/rows");
14
14
  const { isExternalTable, isRowId: isExternalRowId, } = require("../integrations/utils");
15
- const migration = require("../migrations/usageQuotas");
16
15
  // currently only counting new writes and deletes
17
16
  const METHOD_MAP = {
18
17
  POST: 1,
@@ -74,7 +73,6 @@ module.exports = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
74
73
  usage = files.map(file => file.size).reduce((total, size) => total + size);
75
74
  }
76
75
  try {
77
- yield migration.run();
78
76
  yield performRequest(ctx, next, property, usage);
79
77
  }
80
78
  catch (err) {
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.run = void 0;
13
+ const { DocumentTypes } = require("@budibase/backend-core/db");
14
+ const application_1 = require("../../api/controllers/application");
15
+ /**
16
+ * Date:
17
+ * January 2022
18
+ *
19
+ * Description:
20
+ * Add the url to the app metadata if it doesn't exist
21
+ */
22
+ const run = (appDb) => __awaiter(void 0, void 0, void 0, function* () {
23
+ let metadata;
24
+ try {
25
+ metadata = yield appDb.get(DocumentTypes.APP_METADATA);
26
+ }
27
+ catch (e) {
28
+ // sometimes the metadata document doesn't exist
29
+ // exit early instead of failing the migration
30
+ console.error("Error retrieving app metadata. Skipping", e);
31
+ return;
32
+ }
33
+ if (!metadata.url) {
34
+ const context = {
35
+ request: {
36
+ body: {
37
+ name: metadata.name,
38
+ },
39
+ },
40
+ };
41
+ metadata.url = application_1.getAppUrl(context);
42
+ console.log(`Adding url to app: ${metadata.url}`);
43
+ yield appDb.put(metadata);
44
+ }
45
+ });
46
+ exports.run = run;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.run = void 0;
32
+ const usageQuotas_1 = require("./usageQuotas");
33
+ const syncApps = __importStar(require("./usageQuotas/syncApps"));
34
+ const syncRows = __importStar(require("./usageQuotas/syncRows"));
35
+ /**
36
+ * Date:
37
+ * January 2022
38
+ *
39
+ * Description:
40
+ * Synchronise the app and row quotas to the state of the db after it was
41
+ * discovered that the quota resets were still in place and the row quotas
42
+ * weren't being decremented correctly.
43
+ */
44
+ const run = () => __awaiter(void 0, void 0, void 0, function* () {
45
+ yield usageQuotas_1.runQuotaMigration(() => __awaiter(void 0, void 0, void 0, function* () {
46
+ yield syncApps.run();
47
+ yield syncRows.run();
48
+ }));
49
+ });
50
+ exports.run = run;
@@ -8,17 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const { MIGRATIONS, MIGRATION_DBS, migrateIfRequired, } = require("@budibase/backend-core/migrations");
12
- const { useQuotas } = require("../../utilities/usageQuota");
13
- const syncApps = require("./syncApps");
14
- const syncRows = require("./syncRows");
15
- exports.run = () => __awaiter(void 0, void 0, void 0, function* () {
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.runQuotaMigration = void 0;
13
+ const { useQuotas } = require("../../../utilities/usageQuota");
14
+ const runQuotaMigration = (migration) => __awaiter(void 0, void 0, void 0, function* () {
16
15
  if (!useQuotas()) {
17
16
  return;
18
17
  }
19
- // Jan 2022
20
- yield migrateIfRequired(MIGRATION_DBS.GLOBAL_DB, MIGRATIONS.QUOTAS_1, () => __awaiter(void 0, void 0, void 0, function* () {
21
- yield syncApps.run();
22
- yield syncRows.run();
23
- }));
18
+ yield migration();
24
19
  });
20
+ exports.runQuotaMigration = runQuotaMigration;
@@ -8,19 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.run = void 0;
11
16
  const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy");
12
17
  const { getAllApps } = require("@budibase/backend-core/db");
13
- const CouchDB = require("../../db");
14
- const { getUsageQuotaDoc } = require("../../utilities/usageQuota");
15
- exports.run = () => __awaiter(void 0, void 0, void 0, function* () {
18
+ const db_1 = __importDefault(require("../../../db"));
19
+ const usageQuota_1 = require("../../../utilities/usageQuota");
20
+ const run = () => __awaiter(void 0, void 0, void 0, function* () {
16
21
  const db = getGlobalDB();
17
22
  // get app count
18
- const devApps = yield getAllApps(CouchDB, { dev: true });
23
+ const devApps = yield getAllApps(db_1.default, { dev: true });
19
24
  const appCount = devApps ? devApps.length : 0;
20
25
  // sync app count
21
26
  const tenantId = getTenantId();
22
27
  console.log(`[Tenant: ${tenantId}] Syncing app count: ${appCount}`);
23
- const usageDoc = yield getUsageQuotaDoc(db);
28
+ const usageDoc = yield usageQuota_1.getUsageQuotaDoc(db);
24
29
  usageDoc.usageQuota.apps = appCount;
25
30
  yield db.put(usageDoc);
26
31
  });
32
+ exports.run = run;
@@ -8,22 +8,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.run = void 0;
11
16
  const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy");
12
17
  const { getAllApps } = require("@budibase/backend-core/db");
13
- const CouchDB = require("../../db");
14
- const { getUsageQuotaDoc } = require("../../utilities/usageQuota");
15
- const { getUniqueRows } = require("../../utilities/usageQuota/rows");
16
- exports.run = () => __awaiter(void 0, void 0, void 0, function* () {
18
+ const db_1 = __importDefault(require("../../../db"));
19
+ const usageQuota_1 = require("../../../utilities/usageQuota");
20
+ const rows_1 = require("../../../utilities/usageQuota/rows");
21
+ const run = () => __awaiter(void 0, void 0, void 0, function* () {
17
22
  const db = getGlobalDB();
18
23
  // get all rows in all apps
19
- const allApps = yield getAllApps(CouchDB, { all: true });
20
- const appIds = allApps ? allApps.map(app => app.appId) : [];
21
- const rows = yield getUniqueRows(appIds);
24
+ const allApps = yield getAllApps(db_1.default, { all: true });
25
+ const appIds = allApps ? allApps.map((app) => app.appId) : [];
26
+ const rows = yield rows_1.getUniqueRows(appIds);
22
27
  const rowCount = rows ? rows.length : 0;
23
28
  // sync row count
24
29
  const tenantId = getTenantId();
25
30
  console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`);
26
- const usageDoc = yield getUsageQuotaDoc(db);
31
+ const usageDoc = yield usageQuota_1.getUsageQuotaDoc(db);
27
32
  usageDoc.usageQuota.rows = rowCount;
28
33
  yield db.put(usageDoc);
29
34
  });
35
+ exports.run = run;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.run = void 0;
13
+ const { createUserEmailView } = require("@budibase/backend-core/db");
14
+ /**
15
+ * Date:
16
+ * October 2021
17
+ *
18
+ * Description:
19
+ * Recreate the user email view to include latest changes i.e. lower casing the email address
20
+ */
21
+ const run = (db) => __awaiter(void 0, void 0, void 0, function* () {
22
+ yield createUserEmailView(db);
23
+ });
24
+ exports.run = run;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.migrate = exports.MIGRATIONS = void 0;
35
+ const db_1 = __importDefault(require("../db"));
36
+ const { MIGRATION_TYPES, runMigrations, } = require("@budibase/backend-core/migrations");
37
+ // migration functions
38
+ const userEmailViewCasing = __importStar(require("./functions/userEmailViewCasing"));
39
+ const quota1 = __importStar(require("./functions/quotas1"));
40
+ const appUrls = __importStar(require("./functions/appUrls"));
41
+ exports.MIGRATIONS = [
42
+ {
43
+ type: MIGRATION_TYPES.GLOBAL,
44
+ name: "user_email_view_casing",
45
+ fn: userEmailViewCasing.run,
46
+ },
47
+ {
48
+ type: MIGRATION_TYPES.GLOBAL,
49
+ name: "quotas_1",
50
+ fn: quota1.run,
51
+ },
52
+ {
53
+ type: MIGRATION_TYPES.APP,
54
+ name: "app_urls",
55
+ opts: { all: true },
56
+ fn: appUrls.run,
57
+ },
58
+ ];
59
+ const migrate = (options) => __awaiter(void 0, void 0, void 0, function* () {
60
+ yield runMigrations(db_1.default, exports.MIGRATIONS, options);
61
+ });
62
+ exports.migrate = migrate;
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "1.0.48",
4
+ "version": "1.0.49-alpha.3",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -70,9 +70,9 @@
70
70
  "license": "GPL-3.0",
71
71
  "dependencies": {
72
72
  "@apidevtools/swagger-parser": "^10.0.3",
73
- "@budibase/backend-core": "^1.0.48",
74
- "@budibase/client": "^1.0.48",
75
- "@budibase/string-templates": "^1.0.48",
73
+ "@budibase/backend-core": "^1.0.49-alpha.3",
74
+ "@budibase/client": "^1.0.49-alpha.3",
75
+ "@budibase/string-templates": "^1.0.49-alpha.3",
76
76
  "@bull-board/api": "^3.7.0",
77
77
  "@bull-board/koa": "^3.7.0",
78
78
  "@elastic/elasticsearch": "7.10.0",
@@ -44,6 +44,9 @@ class TestConfiguration {
44
44
  getAppId() {
45
45
  return this.appId;
46
46
  }
47
+ getCouch() {
48
+ return CouchDB;
49
+ }
47
50
  _req(config, params, controlFunc) {
48
51
  return __awaiter(this, void 0, void 0, function* () {
49
52
  const request = {};