@budibase/server 1.0.49-alpha.1 → 1.0.49-alpha.2

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 (215) hide show
  1. package/builder/assets/{index.ed1cf508.js → index.82e12602.js} +149 -149
  2. package/builder/assets/{index.ba78c49d.css → index.83c0944f.css} +1 -1
  3. package/builder/index.html +2 -2
  4. package/coverage/clover.xml +989 -1020
  5. package/coverage/coverage-final.json +90 -91
  6. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/application.js.html +106 -106
  9. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
  11. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
  15. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/index.html +27 -12
  17. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
  19. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  20. package/coverage/lcov-report/{migrations/usageQuotas/syncApps.js.html → api/controllers/migrations.js.html} +30 -45
  21. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  22. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  23. package/coverage/lcov-report/api/controllers/query/index.js.html +19 -19
  24. package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
  25. package/coverage/lcov-report/api/controllers/role.js.html +9 -9
  26. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
  28. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/index.js.html +13 -13
  30. package/coverage/lcov-report/api/controllers/row/internal.js.html +26 -26
  31. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +8 -8
  32. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +10 -10
  33. package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
  34. package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
  35. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  36. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +9 -9
  37. package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
  38. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  39. package/coverage/lcov-report/api/controllers/table/index.js.html +14 -14
  40. package/coverage/lcov-report/api/controllers/table/internal.js.html +12 -12
  41. package/coverage/lcov-report/api/controllers/table/utils.js.html +30 -30
  42. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/user.js.html +20 -20
  44. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  45. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  46. package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
  47. package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
  48. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  49. package/coverage/lcov-report/api/controllers/webhook.js.html +15 -15
  50. package/coverage/lcov-report/api/index.html +1 -1
  51. package/coverage/lcov-report/api/index.js.html +3 -3
  52. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/index.html +22 -7
  64. package/coverage/lcov-report/api/routes/index.js.html +10 -4
  65. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  68. package/coverage/lcov-report/{migrations/usageQuotas/index.js.html → api/routes/migrations.js.html} +25 -55
  69. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  80. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  82. package/coverage/lcov-report/automations/actions.js.html +24 -24
  83. package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
  84. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  85. package/coverage/lcov-report/automations/index.html +1 -1
  86. package/coverage/lcov-report/automations/index.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  88. package/coverage/lcov-report/automations/steps/createRow.js.html +7 -7
  89. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  90. package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
  91. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  92. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  93. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  94. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  95. package/coverage/lcov-report/automations/steps/index.html +1 -1
  96. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  97. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  98. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  99. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  100. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  101. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  102. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  103. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  104. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  105. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  106. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  107. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  108. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  109. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  110. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  111. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  112. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  113. package/coverage/lcov-report/automations/triggers.js.html +18 -18
  114. package/coverage/lcov-report/automations/utils.js.html +32 -32
  115. package/coverage/lcov-report/constants/index.html +1 -1
  116. package/coverage/lcov-report/constants/index.js.html +26 -26
  117. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  118. package/coverage/lcov-report/constants/screens.js.html +4 -4
  119. package/coverage/lcov-report/db/client.js.html +18 -18
  120. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  121. package/coverage/lcov-report/db/index.html +1 -1
  122. package/coverage/lcov-report/db/index.js.html +3 -3
  123. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +7 -7
  124. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  125. package/coverage/lcov-report/db/linkedRows/index.js.html +18 -18
  126. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +13 -13
  127. package/coverage/lcov-report/db/newid.js.html +4 -4
  128. package/coverage/lcov-report/db/utils.js.html +70 -70
  129. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  130. package/coverage/lcov-report/events/index.html +1 -1
  131. package/coverage/lcov-report/events/index.js.html +5 -5
  132. package/coverage/lcov-report/events/utils.js.html +3 -3
  133. package/coverage/lcov-report/index.html +26 -41
  134. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  135. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  136. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  137. package/coverage/lcov-report/middleware/authorized.js.html +1 -1
  138. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  139. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  140. package/coverage/lcov-report/middleware/index.html +11 -11
  141. package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
  142. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  143. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  144. package/coverage/lcov-report/middleware/usageQuota.js.html +6 -12
  145. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  146. package/coverage/lcov-report/threads/automation.js.html +1 -1
  147. package/coverage/lcov-report/threads/index.html +1 -1
  148. package/coverage/lcov-report/threads/index.js.html +10 -10
  149. package/coverage/lcov-report/threads/query.js.html +1 -1
  150. package/coverage/lcov-report/threads/utils.js.html +14 -14
  151. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  152. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  153. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  154. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  155. package/coverage/lcov-report/utilities/global.js.html +14 -14
  156. package/coverage/lcov-report/utilities/index.html +1 -1
  157. package/coverage/lcov-report/utilities/index.js.html +24 -24
  158. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
  159. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  160. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  161. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  162. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  163. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +18 -18
  164. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +4 -4
  165. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  166. package/coverage/lcov-report/utilities/security.js.html +8 -8
  167. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  168. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  169. package/coverage/lcov-report/utilities/usageQuota/index.js.html +10 -10
  170. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  171. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  172. package/coverage/lcov-report/utilities/users.js.html +5 -5
  173. package/coverage/lcov-report/utilities/workerRequests.js.html +12 -12
  174. package/coverage/lcov.info +1128 -1176
  175. package/dist/api/controllers/application.js +18 -20
  176. package/dist/api/controllers/migrations.js +21 -0
  177. package/dist/api/routes/index.js +2 -0
  178. package/dist/api/routes/migrations.js +9 -0
  179. package/dist/app.js +35 -5
  180. package/dist/environment.js +1 -0
  181. package/dist/middleware/usageQuota.js +0 -2
  182. package/dist/migrations/functions/appUrls.js +37 -0
  183. package/dist/migrations/functions/quotas1.js +50 -0
  184. package/dist/migrations/{usageQuotas → functions/usageQuotas}/index.js +6 -10
  185. package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncApps.js +11 -5
  186. package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncRows.js +14 -8
  187. package/dist/migrations/functions/userEmailViewCasing.js +24 -0
  188. package/dist/migrations/index.js +62 -0
  189. package/dist/package.json +4 -4
  190. package/dist/tests/utilities/TestConfiguration.js +3 -0
  191. package/dist/tsconfig.tsbuildinfo +1 -1
  192. package/package.json +5 -5
  193. package/src/api/controllers/application.js +3 -3
  194. package/src/api/controllers/migrations.js +13 -0
  195. package/src/api/routes/index.js +2 -0
  196. package/src/api/routes/migrations.js +14 -0
  197. package/src/app.ts +18 -5
  198. package/src/environment.js +1 -0
  199. package/src/middleware/usageQuota.js +0 -2
  200. package/src/migrations/functions/appUrls.ts +25 -0
  201. package/src/migrations/functions/quotas1.ts +20 -0
  202. package/src/migrations/functions/tests/appUrls.spec.js +29 -0
  203. package/src/migrations/{tests/usageQuotas/index.spec.js → functions/tests/quotas1.spec.js} +5 -5
  204. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +25 -0
  205. package/src/migrations/functions/usageQuotas/index.ts +8 -0
  206. package/src/migrations/{usageQuotas/syncApps.js → functions/usageQuotas/syncApps.ts} +3 -3
  207. package/src/migrations/{usageQuotas/syncRows.js → functions/usageQuotas/syncRows.ts} +5 -5
  208. package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncApps.spec.js +4 -4
  209. package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncRows.spec.js +4 -4
  210. package/src/migrations/functions/userEmailViewCasing.ts +13 -0
  211. package/src/migrations/index.ts +56 -0
  212. package/src/tests/utilities/TestConfiguration.js +4 -0
  213. package/coverage/lcov-report/migrations/usageQuotas/index.html +0 -141
  214. package/coverage/lcov-report/migrations/usageQuotas/syncRows.js.html +0 -143
  215. package/src/migrations/usageQuotas/index.js +0 -24
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "1.0.49-alpha.1",
4
+ "version": "1.0.49-alpha.2",
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.49-alpha.1",
74
- "@budibase/client": "^1.0.49-alpha.1",
75
- "@budibase/string-templates": "^1.0.49-alpha.1",
73
+ "@budibase/backend-core": "^1.0.49-alpha.2",
74
+ "@budibase/client": "^1.0.49-alpha.2",
75
+ "@budibase/string-templates": "^1.0.49-alpha.2",
76
76
  "@bull-board/api": "^3.7.0",
77
77
  "@bull-board/koa": "^3.7.0",
78
78
  "@elastic/elasticsearch": "7.10.0",
@@ -168,5 +168,5 @@
168
168
  "optionalDependencies": {
169
169
  "oracledb": "^5.3.0"
170
170
  },
171
- "gitHead": "3f8d81837dd8ba0ebf17dbd8106c3a5d3bec3e46"
171
+ "gitHead": "cb6189e76b22266d2f55c9ad2e4f38639272cd20"
172
172
  }
@@ -75,7 +75,7 @@ function getUserRoleId(ctx) {
75
75
  : ctx.user.role._id
76
76
  }
77
77
 
78
- async function getAppUrl(ctx) {
78
+ exports.getAppUrl = ctx => {
79
79
  // construct the url
80
80
  let url
81
81
  if (ctx.request.body.url) {
@@ -219,7 +219,7 @@ exports.create = async ctx => {
219
219
  const apps = await getAllApps(CouchDB, { dev: true })
220
220
  const name = ctx.request.body.name
221
221
  checkAppName(ctx, apps, name)
222
- const url = await getAppUrl(ctx)
222
+ const url = exports.getAppUrl(ctx)
223
223
  checkAppUrl(ctx, apps, url)
224
224
 
225
225
  const { useTemplate, templateKey, templateString } = ctx.request.body
@@ -286,7 +286,7 @@ exports.update = async ctx => {
286
286
  if (name) {
287
287
  checkAppName(ctx, apps, name, ctx.params.appId)
288
288
  }
289
- const url = await getAppUrl(ctx)
289
+ const url = await exports.getAppUrl(ctx)
290
290
  if (url) {
291
291
  checkAppUrl(ctx, apps, url, ctx.params.appId)
292
292
  ctx.request.body.url = url
@@ -0,0 +1,13 @@
1
+ const { migrate, MIGRATIONS } = require("../../migrations")
2
+
3
+ exports.migrate = async ctx => {
4
+ const options = ctx.request.body
5
+ // don't await as can take a while, just return
6
+ migrate(options)
7
+ ctx.status = 200
8
+ }
9
+
10
+ exports.fetchDefinitions = async ctx => {
11
+ ctx.body = MIGRATIONS
12
+ ctx.status = 200
13
+ }
@@ -24,6 +24,7 @@ const backupRoutes = require("./backup")
24
24
  const metadataRoutes = require("./metadata")
25
25
  const devRoutes = require("./dev")
26
26
  const cloudRoutes = require("./cloud")
27
+ const migrationRoutes = require("./migrations")
27
28
 
28
29
  exports.mainRoutes = [
29
30
  authRoutes,
@@ -53,6 +54,7 @@ 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
 
58
60
  exports.staticRoutes = staticRoutes
@@ -0,0 +1,14 @@
1
+ const Router = require("@koa/router")
2
+ const migrationsController = require("../controllers/migrations")
3
+ const router = Router()
4
+ const { internalApi } = require("@budibase/backend-core/auth")
5
+
6
+ router
7
+ .post("/api/migrations/run", internalApi, migrationsController.migrate)
8
+ .get(
9
+ "/api/migrations/definitions",
10
+ internalApi,
11
+ migrationsController.fetchDefinitions
12
+ )
13
+
14
+ module.exports = router
package/src/app.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // need to load environment first
2
2
  import { ExtendableContext } from "koa"
3
3
 
4
- const env = require("./environment")
4
+ import * as env from "./environment"
5
5
  const CouchDB = require("./db")
6
6
  require("@budibase/backend-core").init(CouchDB)
7
7
  const Koa = require("koa")
@@ -16,6 +16,7 @@ const Sentry = require("@sentry/node")
16
16
  const fileSystem = require("./utilities/fileSystem")
17
17
  const bullboard = require("./automations/bullboard")
18
18
  const redis = require("./utilities/redis")
19
+ import * as migrations from "./migrations"
19
20
 
20
21
  const app = new Koa()
21
22
 
@@ -84,13 +85,25 @@ module.exports = server.listen(env.PORT || 0, async () => {
84
85
  await automations.init()
85
86
  })
86
87
 
87
- process.on("uncaughtException", err => {
88
- console.error(err)
88
+ const shutdown = () => {
89
89
  server.close()
90
90
  server.destroy()
91
+ }
92
+
93
+ process.on("uncaughtException", err => {
94
+ console.error(err)
95
+ shutdown()
91
96
  })
92
97
 
93
98
  process.on("SIGTERM", () => {
94
- server.close()
95
- server.destroy()
99
+ shutdown()
96
100
  })
101
+
102
+ // run migrations on startup if not done via http
103
+ // not recommended in a clustered environment
104
+ if (!env.HTTP_MIGRATIONS) {
105
+ migrations.migrate().catch(err => {
106
+ console.error("Error performing migrations. Exiting.\n", err)
107
+ shutdown()
108
+ })
109
+ }
@@ -43,6 +43,7 @@ module.exports = {
43
43
  REDIS_PASSWORD: process.env.REDIS_PASSWORD,
44
44
  INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
45
45
  MULTI_TENANCY: process.env.MULTI_TENANCY,
46
+ HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
46
47
  // environment
47
48
  NODE_ENV: process.env.NODE_ENV,
48
49
  JEST_WORKER_ID: process.env.JEST_WORKER_ID,
@@ -5,7 +5,6 @@ const {
5
5
  isExternalTable,
6
6
  isRowId: isExternalRowId,
7
7
  } = require("../integrations/utils")
8
- const migration = require("../migrations/usageQuotas")
9
8
 
10
9
  // currently only counting new writes and deletes
11
10
  const METHOD_MAP = {
@@ -74,7 +73,6 @@ module.exports = async (ctx, next) => {
74
73
  usage = files.map(file => file.size).reduce((total, size) => total + size)
75
74
  }
76
75
  try {
77
- await migration.run()
78
76
  await performRequest(ctx, next, property, usage)
79
77
  } catch (err) {
80
78
  ctx.throw(400, err)
@@ -0,0 +1,25 @@
1
+ const { DocumentTypes } = require("@budibase/backend-core/db")
2
+ import { getAppUrl } from "../../api/controllers/application"
3
+
4
+ /**
5
+ * Date:
6
+ * January 2022
7
+ *
8
+ * Description:
9
+ * Add the url to the app metadata if it doesn't exist
10
+ */
11
+ export const run = async (appDb: any) => {
12
+ const metadata = await appDb.get(DocumentTypes.APP_METADATA)
13
+ if (!metadata.url) {
14
+ const context = {
15
+ request: {
16
+ body: {
17
+ name: metadata.name,
18
+ },
19
+ },
20
+ }
21
+ metadata.url = getAppUrl(context)
22
+ console.log(`Adding url to app: ${metadata.url}`)
23
+ }
24
+ await appDb.put(metadata)
25
+ }
@@ -0,0 +1,20 @@
1
+ import { runQuotaMigration } from "./usageQuotas"
2
+ import * as syncApps from "./usageQuotas/syncApps"
3
+ import * as syncRows from "./usageQuotas/syncRows"
4
+
5
+ /**
6
+ * Date:
7
+ * January 2022
8
+ *
9
+ * Description:
10
+ * Synchronise the app and row quotas to the state of the db after it was
11
+ * discovered that the quota resets were still in place and the row quotas
12
+ * weren't being decremented correctly.
13
+ */
14
+
15
+ export const run = async () => {
16
+ await runQuotaMigration(async () => {
17
+ await syncApps.run()
18
+ await syncRows.run()
19
+ })
20
+ }
@@ -0,0 +1,29 @@
1
+ const { DocumentTypes } = require("@budibase/backend-core/db")
2
+ const env = require("../../../environment")
3
+ const TestConfig = require("../../../tests/utilities/TestConfiguration")
4
+
5
+ const migration = require("../appUrls")
6
+
7
+ describe("run", () => {
8
+ let config = new TestConfig(false)
9
+ const CouchDB = config.getCouch()
10
+
11
+ beforeEach(async () => {
12
+ await config.init()
13
+ })
14
+
15
+ afterAll(config.end)
16
+
17
+ it("runs successfully", async () => {
18
+ const app = await config.createApp("testApp")
19
+ const appDb = new CouchDB(app.appId)
20
+ let metadata = await appDb.get(DocumentTypes.APP_METADATA)
21
+ delete metadata.url
22
+ await appDb.put(metadata)
23
+
24
+ await migration.run(appDb)
25
+
26
+ metadata = await appDb.get(DocumentTypes.APP_METADATA)
27
+ expect(metadata.url).toEqual("/testapp")
28
+ })
29
+ })
@@ -4,10 +4,10 @@ const TestConfig = require("../../../tests/utilities/TestConfiguration")
4
4
  const syncApps = jest.fn()
5
5
  const syncRows = jest.fn()
6
6
 
7
- jest.mock("../../usageQuotas/syncApps", () => ({ run: syncApps }) )
8
- jest.mock("../../usageQuotas/syncRows", () => ({ run: syncRows }) )
7
+ jest.mock("../usageQuotas/syncApps", () => ({ run: syncApps }) )
8
+ jest.mock("../usageQuotas/syncRows", () => ({ run: syncRows }) )
9
9
 
10
- const migrations = require("../../usageQuotas")
10
+ const migration = require("../quotas1")
11
11
 
12
12
  describe("run", () => {
13
13
  let config = new TestConfig(false)
@@ -19,8 +19,8 @@ describe("run", () => {
19
19
 
20
20
  afterAll(config.end)
21
21
 
22
- it("runs the required migrations", async () => {
23
- await migrations.run()
22
+ it("runs ", async () => {
23
+ await migration.run()
24
24
  expect(syncApps).toHaveBeenCalledTimes(1)
25
25
  expect(syncRows).toHaveBeenCalledTimes(1)
26
26
  })
@@ -0,0 +1,25 @@
1
+ const TestConfig = require("../../../tests/utilities/TestConfiguration")
2
+ const { getGlobalDB } = require("@budibase/backend-core/tenancy")
3
+
4
+ // mock email view creation
5
+ const coreDb = require("@budibase/backend-core/db")
6
+ const createUserEmailView = jest.fn()
7
+ coreDb.createUserEmailView = createUserEmailView
8
+
9
+ const migration = require("../userEmailViewCasing")
10
+
11
+ describe("run", () => {
12
+ let config = new TestConfig(false)
13
+ const globalDb = getGlobalDB()
14
+
15
+ beforeEach(async () => {
16
+ await config.init()
17
+ })
18
+
19
+ afterAll(config.end)
20
+
21
+ it("runs successfully", async () => {
22
+ await migration.run(globalDb)
23
+ expect(createUserEmailView).toHaveBeenCalledTimes(1)
24
+ })
25
+ })
@@ -0,0 +1,8 @@
1
+ const { useQuotas } = require("../../../utilities/usageQuota")
2
+
3
+ export const runQuotaMigration = async (migration: Function) => {
4
+ if (!useQuotas()) {
5
+ return
6
+ }
7
+ await migration()
8
+ }
@@ -1,9 +1,9 @@
1
1
  const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy")
2
2
  const { getAllApps } = require("@budibase/backend-core/db")
3
- const CouchDB = require("../../db")
4
- const { getUsageQuotaDoc } = require("../../utilities/usageQuota")
3
+ import CouchDB from "../../../db"
4
+ import { getUsageQuotaDoc } from "../../../utilities/usageQuota"
5
5
 
6
- exports.run = async () => {
6
+ export const run = async () => {
7
7
  const db = getGlobalDB()
8
8
  // get app count
9
9
  const devApps = await getAllApps(CouchDB, { dev: true })
@@ -1,14 +1,14 @@
1
1
  const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy")
2
2
  const { getAllApps } = require("@budibase/backend-core/db")
3
- const CouchDB = require("../../db")
4
- const { getUsageQuotaDoc } = require("../../utilities/usageQuota")
5
- const { getUniqueRows } = require("../../utilities/usageQuota/rows")
3
+ import CouchDB from "../../../db"
4
+ import { getUsageQuotaDoc } from "../../../utilities/usageQuota"
5
+ import { getUniqueRows } from "../../../utilities/usageQuota/rows"
6
6
 
7
- exports.run = async () => {
7
+ export const run = async () => {
8
8
  const db = getGlobalDB()
9
9
  // get all rows in all apps
10
10
  const allApps = await getAllApps(CouchDB, { all: true })
11
- const appIds = allApps ? allApps.map(app => app.appId) : []
11
+ const appIds = allApps ? allApps.map((app: { appId: any }) => app.appId) : []
12
12
  const rows = await getUniqueRows(appIds)
13
13
  const rowCount = rows ? rows.length : 0
14
14
 
@@ -1,8 +1,8 @@
1
1
  const { getGlobalDB } = require("@budibase/backend-core/tenancy")
2
- const TestConfig = require("../../../tests/utilities/TestConfiguration")
3
- const { getUsageQuotaDoc, update, Properties } = require("../../../utilities/usageQuota")
4
- const syncApps = require("../../usageQuotas/syncApps")
5
- const env = require("../../../environment")
2
+ const TestConfig = require("../../../../tests/utilities/TestConfiguration")
3
+ const { getUsageQuotaDoc, update, Properties } = require("../../../../utilities/usageQuota")
4
+ const syncApps = require("../syncApps")
5
+ const env = require("../../../../environment")
6
6
 
7
7
  describe("syncApps", () => {
8
8
  let config = new TestConfig(false)
@@ -1,8 +1,8 @@
1
1
  const { getGlobalDB } = require("@budibase/backend-core/tenancy")
2
- const TestConfig = require("../../../tests/utilities/TestConfiguration")
3
- const { getUsageQuotaDoc, update, Properties } = require("../../../utilities/usageQuota")
4
- const syncRows = require("../../usageQuotas/syncRows")
5
- const env = require("../../../environment")
2
+ const TestConfig = require("../../../../tests/utilities/TestConfiguration")
3
+ const { getUsageQuotaDoc, update, Properties } = require("../../../../utilities/usageQuota")
4
+ const syncRows = require("../syncRows")
5
+ const env = require("../../../../environment")
6
6
 
7
7
  describe("syncRows", () => {
8
8
  let config = new TestConfig(false)
@@ -0,0 +1,13 @@
1
+ const { createUserEmailView } = require("@budibase/backend-core/db")
2
+
3
+ /**
4
+ * Date:
5
+ * October 2021
6
+ *
7
+ * Description:
8
+ * Recreate the user email view to include latest changes i.e. lower casing the email address
9
+ */
10
+
11
+ export const run = async (db: any) => {
12
+ await createUserEmailView(db)
13
+ }
@@ -0,0 +1,56 @@
1
+ import CouchDB from "../db"
2
+ const {
3
+ MIGRATION_TYPES,
4
+ runMigrations,
5
+ } = require("@budibase/backend-core/migrations")
6
+
7
+ // migration functions
8
+ import * as userEmailViewCasing from "./functions/userEmailViewCasing"
9
+ import * as quota1 from "./functions/quotas1"
10
+ import * as appUrls from "./functions/appUrls"
11
+
12
+ export interface Migration {
13
+ type: string
14
+ name: string
15
+ opts?: object
16
+ fn: Function
17
+ }
18
+
19
+ /**
20
+ * e.g.
21
+ * {
22
+ * tenantIds: ['bb'],
23
+ * force: {
24
+ * global: ['quota_1']
25
+ * }
26
+ * }
27
+ */
28
+ export interface MigrationOptions {
29
+ tenantIds?: string[]
30
+ forced?: {
31
+ [type: string]: string[]
32
+ }
33
+ }
34
+
35
+ export const MIGRATIONS: Migration[] = [
36
+ {
37
+ type: MIGRATION_TYPES.GLOBAL,
38
+ name: "user_email_view_casing",
39
+ fn: userEmailViewCasing.run,
40
+ },
41
+ {
42
+ type: MIGRATION_TYPES.GLOBAL,
43
+ name: "quotas_1",
44
+ fn: quota1.run,
45
+ },
46
+ {
47
+ type: MIGRATION_TYPES.APP,
48
+ name: "app_urls",
49
+ opts: { all: true },
50
+ fn: appUrls.run,
51
+ },
52
+ ]
53
+
54
+ export const migrate = async (options?: MigrationOptions) => {
55
+ await runMigrations(CouchDB, MIGRATIONS, options)
56
+ }
@@ -50,6 +50,10 @@ class TestConfiguration {
50
50
  return this.appId
51
51
  }
52
52
 
53
+ getCouch() {
54
+ return CouchDB
55
+ }
56
+
53
57
  async _req(config, params, controlFunc) {
54
58
  const request = {}
55
59
  // fake cookies, we don't need them
@@ -1,141 +0,0 @@
1
-
2
- <!doctype html>
3
- <html lang="en">
4
-
5
- <head>
6
- <title>Code coverage report for migrations/usageQuotas</title>
7
- <meta charset="utf-8" />
8
- <link rel="stylesheet" href="../../prettify.css" />
9
- <link rel="stylesheet" href="../../base.css" />
10
- <link rel="shortcut icon" type="image/x-icon" href="../../favicon.png" />
11
- <meta name="viewport" content="width=device-width, initial-scale=1" />
12
- <style type='text/css'>
13
- .coverage-summary .sorter {
14
- background-image: url(../../sort-arrow-sprite.png);
15
- }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <div class='wrapper'>
21
- <div class='pad1'>
22
- <h1><a href="../../index.html">All files</a> migrations/usageQuotas</h1>
23
- <div class='clearfix'>
24
-
25
- <div class='fl pad1y space-right2'>
26
- <span class="strong">100% </span>
27
- <span class="quiet">Statements</span>
28
- <span class='fraction'>40/40</span>
29
- </div>
30
-
31
-
32
- <div class='fl pad1y space-right2'>
33
- <span class="strong">62.5% </span>
34
- <span class="quiet">Branches</span>
35
- <span class='fraction'>5/8</span>
36
- </div>
37
-
38
-
39
- <div class='fl pad1y space-right2'>
40
- <span class="strong">100% </span>
41
- <span class="quiet">Functions</span>
42
- <span class='fraction'>5/5</span>
43
- </div>
44
-
45
-
46
- <div class='fl pad1y space-right2'>
47
- <span class="strong">100% </span>
48
- <span class="quiet">Lines</span>
49
- <span class='fraction'>39/39</span>
50
- </div>
51
-
52
-
53
- </div>
54
- <p class="quiet">
55
- Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
56
- </p>
57
- </div>
58
- <div class='status-line high'></div>
59
- <div class="pad1">
60
- <table class="coverage-summary">
61
- <thead>
62
- <tr>
63
- <th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
64
- <th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
65
- <th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
66
- <th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
67
- <th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
68
- <th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
69
- <th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
70
- <th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
71
- <th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
72
- <th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
73
- </tr>
74
- </thead>
75
- <tbody><tr>
76
- <td class="file high" data-value="index.js"><a href="index.js.html">index.js</a></td>
77
- <td data-value="100" class="pic high">
78
- <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
79
- </td>
80
- <td data-value="100" class="pct high">100%</td>
81
- <td data-value="10" class="abs high">10/10</td>
82
- <td data-value="100" class="pct high">100%</td>
83
- <td data-value="2" class="abs high">2/2</td>
84
- <td data-value="100" class="pct high">100%</td>
85
- <td data-value="2" class="abs high">2/2</td>
86
- <td data-value="100" class="pct high">100%</td>
87
- <td data-value="10" class="abs high">10/10</td>
88
- </tr>
89
-
90
- <tr>
91
- <td class="file high" data-value="syncApps.js"><a href="syncApps.js.html">syncApps.js</a></td>
92
- <td data-value="100" class="pic high">
93
- <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
94
- </td>
95
- <td data-value="100" class="pct high">100%</td>
96
- <td data-value="13" class="abs high">13/13</td>
97
- <td data-value="50" class="pct medium">50%</td>
98
- <td data-value="2" class="abs medium">1/2</td>
99
- <td data-value="100" class="pct high">100%</td>
100
- <td data-value="1" class="abs high">1/1</td>
101
- <td data-value="100" class="pct high">100%</td>
102
- <td data-value="13" class="abs high">13/13</td>
103
- </tr>
104
-
105
- <tr>
106
- <td class="file high" data-value="syncRows.js"><a href="syncRows.js.html">syncRows.js</a></td>
107
- <td data-value="100" class="pic high">
108
- <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
109
- </td>
110
- <td data-value="100" class="pct high">100%</td>
111
- <td data-value="17" class="abs high">17/17</td>
112
- <td data-value="50" class="pct medium">50%</td>
113
- <td data-value="4" class="abs medium">2/4</td>
114
- <td data-value="100" class="pct high">100%</td>
115
- <td data-value="2" class="abs high">2/2</td>
116
- <td data-value="100" class="pct high">100%</td>
117
- <td data-value="16" class="abs high">16/16</td>
118
- </tr>
119
-
120
- </tbody>
121
- </table>
122
- </div>
123
- <div class='push'></div><!-- for sticky footer -->
124
- </div><!-- /wrapper -->
125
- <div class='footer quiet pad2 space-top1 center small'>
126
- Code coverage generated by
127
- <a href="https://istanbul.js.org/" target="_blank">istanbul</a>
128
- at Mon Jan 31 2022 16:01:47 GMT+0000 (Coordinated Universal Time)
129
- </div>
130
- </div>
131
- <script src="../../prettify.js"></script>
132
- <script>
133
- window.onload = function () {
134
- prettyPrint();
135
- };
136
- </script>
137
- <script src="../../sorter.js"></script>
138
- <script src="../../block-navigation.js"></script>
139
- </body>
140
- </html>
141
-