@budibase/server 1.0.199 → 1.0.200-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 (281) hide show
  1. package/Dockerfile +2 -0
  2. package/builder/assets/index.359da19e.js +1315 -0
  3. package/builder/index.html +1 -1
  4. package/coverage/clover.xml +2089 -2001
  5. package/coverage/coverage-final.json +121 -122
  6. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  7. package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
  8. package/coverage/lcov-report/api/controllers/automation.js.html +174 -72
  9. package/coverage/lcov-report/api/controllers/backup.js.html +30 -6
  10. package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
  11. package/coverage/lcov-report/api/controllers/component.js.html +5 -5
  12. package/coverage/lcov-report/api/controllers/datasource.js.html +53 -41
  13. package/coverage/lcov-report/api/controllers/dev.js.html +94 -70
  14. package/coverage/lcov-report/api/controllers/index.html +57 -72
  15. package/coverage/lcov-report/api/controllers/integration.js.html +8 -8
  16. package/coverage/lcov-report/api/controllers/layout.js.html +28 -19
  17. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  18. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  19. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  20. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
  22. package/coverage/lcov-report/api/controllers/role.js.html +78 -48
  23. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  24. package/coverage/lcov-report/api/controllers/row/external.js.html +19 -19
  25. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/internal.js.html +54 -54
  27. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +9 -9
  28. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
  29. package/coverage/lcov-report/api/controllers/row/utils.js.html +24 -24
  30. package/coverage/lcov-report/api/controllers/screen.js.html +56 -20
  31. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  32. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
  33. package/coverage/lcov-report/api/controllers/table/external.js.html +23 -17
  34. package/coverage/lcov-report/api/controllers/table/index.html +26 -26
  35. package/coverage/lcov-report/api/controllers/table/index.js.html +85 -49
  36. package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
  37. package/coverage/lcov-report/api/controllers/user.js.html +19 -19
  38. package/coverage/lcov-report/api/controllers/view/exporters.js.html +11 -11
  39. package/coverage/lcov-report/api/controllers/view/index.html +21 -21
  40. package/coverage/lcov-report/api/controllers/view/index.js.html +275 -65
  41. package/coverage/lcov-report/api/controllers/view/utils.js.html +23 -23
  42. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +40 -40
  43. package/coverage/lcov-report/api/controllers/webhook.js.html +17 -17
  44. package/coverage/lcov-report/api/index.html +15 -15
  45. package/coverage/lcov-report/api/index.js.html +39 -45
  46. package/coverage/lcov-report/api/routes/analytics.js.html +7 -13
  47. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  48. package/coverage/lcov-report/api/routes/auth.js.html +6 -6
  49. package/coverage/lcov-report/api/routes/automation.js.html +11 -11
  50. package/coverage/lcov-report/api/routes/backup.js.html +8 -8
  51. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  52. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  53. package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
  54. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  55. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  56. package/coverage/lcov-report/api/routes/index.html +1 -1
  57. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  58. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  59. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  60. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  61. package/coverage/lcov-report/api/routes/permission.js.html +9 -9
  62. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  63. package/coverage/lcov-report/api/routes/role.js.html +9 -9
  64. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  65. package/coverage/lcov-report/api/routes/screen.js.html +9 -9
  66. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/table.js.html +10 -10
  68. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  69. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  70. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  71. package/coverage/lcov-report/api/routes/utils/validators.js.html +36 -36
  72. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  73. package/coverage/lcov-report/api/routes/webhook.js.html +9 -9
  74. package/coverage/lcov-report/automations/actions.js.html +25 -25
  75. package/coverage/lcov-report/automations/automationUtils.js.html +8 -8
  76. package/coverage/lcov-report/automations/bullboard.js.html +35 -35
  77. package/coverage/lcov-report/automations/index.html +29 -29
  78. package/coverage/lcov-report/automations/index.js.html +29 -17
  79. package/coverage/lcov-report/automations/steps/bash.js.html +7 -7
  80. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  81. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  82. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  83. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  84. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  85. package/coverage/lcov-report/automations/steps/index.html +1 -1
  86. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  87. package/coverage/lcov-report/automations/steps/loop.js.html +2 -2
  88. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  89. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  90. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  91. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  92. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  93. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  94. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  95. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  96. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  97. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  98. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  100. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  101. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  102. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  103. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  104. package/coverage/lcov-report/automations/triggers.js.html +18 -18
  105. package/coverage/lcov-report/constants/index.html +1 -1
  106. package/coverage/lcov-report/constants/index.js.html +30 -30
  107. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  108. package/coverage/lcov-report/constants/screens.js.html +4 -4
  109. package/coverage/lcov-report/db/inMemoryView.js.html +5 -5
  110. package/coverage/lcov-report/db/index.html +1 -1
  111. package/coverage/lcov-report/db/index.js.html +9 -9
  112. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
  113. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  114. package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
  115. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +19 -19
  116. package/coverage/lcov-report/db/newid.js.html +4 -4
  117. package/coverage/lcov-report/db/utils.js.html +81 -81
  118. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  119. package/coverage/lcov-report/events/index.html +1 -1
  120. package/coverage/lcov-report/events/index.js.html +7 -7
  121. package/coverage/lcov-report/events/utils.js.html +10 -10
  122. package/coverage/lcov-report/index.html +74 -74
  123. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  124. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  125. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  126. package/coverage/lcov-report/middleware/builder.js.html +20 -20
  127. package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
  128. package/coverage/lcov-report/middleware/index.html +1 -1
  129. package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
  130. package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
  131. package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
  132. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  133. package/coverage/lcov-report/middleware/utils.js.html +4 -4
  134. package/coverage/lcov-report/threads/automation.js.html +1 -1
  135. package/coverage/lcov-report/threads/index.html +1 -1
  136. package/coverage/lcov-report/threads/query.js.html +1 -1
  137. package/coverage/lcov-report/threads/utils.js.html +13 -13
  138. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  139. package/coverage/lcov-report/utilities/centralPath.js.html +14 -14
  140. package/coverage/lcov-report/utilities/csvParser.js.html +34 -34
  141. package/coverage/lcov-report/utilities/global.js.html +28 -28
  142. package/coverage/lcov-report/utilities/index.html +25 -25
  143. package/coverage/lcov-report/utilities/index.js.html +41 -41
  144. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +18 -18
  145. package/coverage/lcov-report/utilities/queue/index.html +15 -15
  146. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  147. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  148. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  149. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +59 -59
  150. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
  151. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  152. package/coverage/lcov-report/utilities/security.js.html +8 -8
  153. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  154. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  155. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +30 -30
  156. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  157. package/coverage/lcov-report/utilities/users.js.html +7 -7
  158. package/coverage/lcov-report/utilities/workerRequests.js.html +29 -29
  159. package/coverage/lcov.info +2903 -2762
  160. package/dist/api/controllers/analytics.js +7 -30
  161. package/dist/api/controllers/application.js +56 -16
  162. package/dist/api/controllers/automation.js +31 -2
  163. package/dist/api/controllers/backup.js +7 -0
  164. package/dist/api/controllers/datasource.js +8 -2
  165. package/dist/api/controllers/deploy/index.js +6 -2
  166. package/dist/api/controllers/dev.js +9 -2
  167. package/dist/api/controllers/layout.js +3 -0
  168. package/dist/api/controllers/query/import/index.js +12 -2
  169. package/dist/api/controllers/query/import/sources/curl.js +3 -0
  170. package/dist/api/controllers/query/import/sources/openapi2.js +3 -0
  171. package/dist/api/controllers/query/import/sources/openapi3.js +3 -0
  172. package/dist/api/controllers/query/index.js +16 -2
  173. package/dist/api/controllers/role.js +11 -0
  174. package/dist/api/controllers/screen.js +10 -1
  175. package/dist/api/controllers/static/index.js +29 -15
  176. package/dist/api/controllers/table/external.js +2 -0
  177. package/dist/api/controllers/table/index.js +12 -0
  178. package/dist/api/controllers/table/utils.js +3 -3
  179. package/dist/api/controllers/view/index.js +62 -6
  180. package/dist/api/index.js +2 -4
  181. package/dist/api/routes/analytics.js +1 -3
  182. package/dist/app.js +16 -8
  183. package/dist/automations/index.js +4 -0
  184. package/dist/environment.js +4 -2
  185. package/dist/migrations/functions/backfill/app/automations.js +31 -0
  186. package/dist/migrations/functions/backfill/app/datasources.js +28 -0
  187. package/dist/migrations/functions/backfill/app/layouts.js +33 -0
  188. package/dist/migrations/functions/backfill/app/queries.js +32 -0
  189. package/dist/migrations/functions/backfill/app/roles.js +28 -0
  190. package/dist/migrations/functions/backfill/app/screens.js +28 -0
  191. package/dist/migrations/functions/backfill/app/tables.js +40 -0
  192. package/dist/migrations/functions/backfill/app.js +175 -0
  193. package/dist/migrations/functions/backfill/global/configs.js +61 -0
  194. package/dist/migrations/functions/backfill/global/quotas.js +60 -0
  195. package/dist/migrations/functions/backfill/global/users.js +50 -0
  196. package/dist/migrations/functions/backfill/global.js +189 -0
  197. package/dist/migrations/functions/backfill/index.js +32 -0
  198. package/dist/migrations/functions/backfill/installation.js +81 -0
  199. package/dist/migrations/index.js +95 -31
  200. package/dist/migrations/tests/helpers.js +72 -0
  201. package/dist/migrations/tests/structures.js +37 -0
  202. package/dist/package.json +79 -69
  203. package/dist/tests/utilities/TestConfiguration.js +121 -93
  204. package/dist/tests/utilities/structures.js +45 -0
  205. package/dist/tsconfig.build.tsbuildinfo +1 -1
  206. package/nodemon.json +1 -1
  207. package/package.json +80 -70
  208. package/scripts/dev/manage.js +2 -0
  209. package/scripts/jestSetup.js +7 -0
  210. package/scripts/likeCypress.ts +1 -1
  211. package/src/api/controllers/analytics.ts +8 -0
  212. package/src/api/controllers/application.ts +60 -18
  213. package/src/api/controllers/automation.js +36 -2
  214. package/src/api/controllers/backup.js +8 -0
  215. package/src/api/controllers/datasource.js +8 -4
  216. package/src/api/controllers/deploy/index.ts +6 -2
  217. package/src/api/controllers/dev.js +10 -2
  218. package/src/api/controllers/layout.js +3 -0
  219. package/src/api/controllers/query/import/index.ts +16 -3
  220. package/src/api/controllers/query/import/sources/base/index.ts +2 -1
  221. package/src/api/controllers/query/import/sources/curl.ts +4 -0
  222. package/src/api/controllers/query/import/sources/openapi2.ts +4 -0
  223. package/src/api/controllers/query/import/sources/openapi3.ts +4 -0
  224. package/src/api/controllers/query/import/tests/index.spec.js +20 -7
  225. package/src/api/controllers/query/index.ts +16 -3
  226. package/src/api/controllers/role.js +10 -0
  227. package/src/api/controllers/screen.js +13 -1
  228. package/src/api/controllers/static/index.js +28 -15
  229. package/src/api/controllers/table/external.js +2 -0
  230. package/src/api/controllers/table/index.js +12 -0
  231. package/src/api/controllers/table/utils.ts +4 -4
  232. package/src/api/controllers/view/index.js +76 -6
  233. package/src/api/index.js +2 -4
  234. package/src/api/routes/analytics.js +1 -3
  235. package/src/api/routes/public/utils/Endpoint.ts +1 -1
  236. package/src/api/routes/tests/__snapshots__/datasource.spec.js.snap +5 -1
  237. package/src/api/routes/tests/application.spec.js +64 -4
  238. package/src/api/routes/tests/automation.spec.js +168 -60
  239. package/src/api/routes/tests/backup.spec.js +2 -0
  240. package/src/api/routes/tests/data/export.txt +1 -0
  241. package/src/api/routes/tests/datasource.spec.js +5 -0
  242. package/src/api/routes/tests/deployment.spec.js +25 -0
  243. package/src/api/routes/tests/dev.spec.js +40 -0
  244. package/src/api/routes/tests/layout.spec.js +4 -0
  245. package/src/api/routes/tests/query.spec.js +56 -13
  246. package/src/api/routes/tests/role.spec.js +40 -7
  247. package/src/api/routes/tests/row.spec.js +2 -3
  248. package/src/api/routes/tests/screen.spec.js +30 -4
  249. package/src/api/routes/tests/static.spec.js +120 -54
  250. package/src/api/routes/tests/table.spec.js +102 -38
  251. package/src/api/routes/tests/view.spec.js +222 -43
  252. package/src/app.ts +18 -9
  253. package/src/automations/index.js +4 -0
  254. package/src/automations/tests/delay.spec.js +4 -0
  255. package/src/environment.js +5 -2
  256. package/src/migrations/functions/backfill/app/automations.ts +26 -0
  257. package/src/migrations/functions/backfill/app/datasources.ts +22 -0
  258. package/src/migrations/functions/backfill/app/layouts.ts +29 -0
  259. package/src/migrations/functions/backfill/app/queries.ts +33 -0
  260. package/src/migrations/functions/backfill/app/roles.ts +22 -0
  261. package/src/migrations/functions/backfill/app/screens.ts +22 -0
  262. package/src/migrations/functions/backfill/app/tables.ts +36 -0
  263. package/src/migrations/functions/backfill/app.ts +148 -0
  264. package/src/migrations/functions/backfill/global/configs.ts +66 -0
  265. package/src/migrations/functions/backfill/global/quotas.ts +60 -0
  266. package/src/migrations/functions/backfill/global/users.ts +49 -0
  267. package/src/migrations/functions/backfill/global.ts +194 -0
  268. package/src/migrations/functions/backfill/index.ts +7 -0
  269. package/src/migrations/functions/backfill/installation.ts +51 -0
  270. package/src/migrations/index.ts +120 -51
  271. package/src/migrations/tests/helpers.ts +40 -0
  272. package/src/migrations/tests/index.spec.ts +132 -0
  273. package/src/migrations/tests/structures.ts +66 -0
  274. package/src/module.d.ts +0 -1
  275. package/src/tests/utilities/TestConfiguration.js +138 -90
  276. package/src/tests/utilities/structures.js +71 -0
  277. package/tsconfig.build.json +20 -5
  278. package/tsconfig.json +22 -17
  279. package/builder/assets/index.107ba2e5.js +0 -1315
  280. package/coverage/lcov-report/api/controllers/analytics.js.html +0 -202
  281. package/src/api/controllers/analytics.js +0 -39
@@ -1,7 +1,6 @@
1
- const {
2
- MIGRATION_TYPES,
3
- runMigrations,
4
- } = require("@budibase/backend-core/migrations")
1
+ import { migrations, redis } from "@budibase/backend-core"
2
+ import { Migration, MigrationOptions, MigrationName } from "@budibase/types"
3
+ import env from "../environment"
5
4
 
6
5
  // migration functions
7
6
  import * as userEmailViewCasing from "./functions/userEmailViewCasing"
@@ -9,59 +8,129 @@ import * as quota1 from "./functions/quotas1"
9
8
  import * as appUrls from "./functions/appUrls"
10
9
  import * as developerQuota from "./functions/developerQuota"
11
10
  import * as publishedAppsQuota from "./functions/publishedAppsQuota"
12
-
13
- export interface Migration {
14
- type: string
15
- name: string
16
- opts?: object
17
- fn: Function
18
- }
11
+ import * as backfill from "./functions/backfill"
19
12
 
20
13
  /**
21
- * e.g.
22
- * {
23
- * tenantIds: ['bb'],
24
- * force: {
25
- * global: ['quota_1']
26
- * }
27
- * }
14
+ * Populate the migration function and additional configuration from
15
+ * the static migration definitions.
28
16
  */
29
- export interface MigrationOptions {
30
- tenantIds?: string[]
31
- force?: {
32
- [type: string]: string[]
17
+ export const buildMigrations = () => {
18
+ const definitions = migrations.DEFINITIONS
19
+ const serverMigrations: Migration[] = []
20
+
21
+ for (const definition of definitions) {
22
+ switch (definition.name) {
23
+ case MigrationName.USER_EMAIL_VIEW_CASING: {
24
+ serverMigrations.push({
25
+ ...definition,
26
+ fn: userEmailViewCasing.run,
27
+ })
28
+ break
29
+ }
30
+ case MigrationName.QUOTAS_1: {
31
+ serverMigrations.push({
32
+ ...definition,
33
+ fn: quota1.run,
34
+ })
35
+ break
36
+ }
37
+ case MigrationName.APP_URLS: {
38
+ serverMigrations.push({
39
+ ...definition,
40
+ appOpts: { all: true },
41
+ fn: appUrls.run,
42
+ })
43
+ break
44
+ }
45
+ case MigrationName.DEVELOPER_QUOTA: {
46
+ serverMigrations.push({
47
+ ...definition,
48
+ fn: developerQuota.run,
49
+ })
50
+ break
51
+ }
52
+ case MigrationName.PUBLISHED_APP_QUOTA: {
53
+ serverMigrations.push({
54
+ ...definition,
55
+ fn: publishedAppsQuota.run,
56
+ })
57
+ break
58
+ }
59
+ case MigrationName.EVENT_APP_BACKFILL: {
60
+ serverMigrations.push({
61
+ ...definition,
62
+ appOpts: { all: true },
63
+ fn: backfill.app.run,
64
+ silent: !!env.SELF_HOSTED, // reduce noisy logging
65
+ preventRetry: !!env.SELF_HOSTED, // only ever run once
66
+ })
67
+ break
68
+ }
69
+ case MigrationName.EVENT_GLOBAL_BACKFILL: {
70
+ serverMigrations.push({
71
+ ...definition,
72
+ fn: backfill.global.run,
73
+ silent: !!env.SELF_HOSTED, // reduce noisy logging
74
+ preventRetry: !!env.SELF_HOSTED, // only ever run once
75
+ })
76
+ break
77
+ }
78
+ case MigrationName.EVENT_INSTALLATION_BACKFILL: {
79
+ serverMigrations.push({
80
+ ...definition,
81
+ fn: backfill.installation.run,
82
+ silent: !!env.SELF_HOSTED, // reduce noisy logging
83
+ preventRetry: !!env.SELF_HOSTED, // only ever run once
84
+ })
85
+ break
86
+ }
87
+ }
33
88
  }
89
+
90
+ return serverMigrations
34
91
  }
35
92
 
36
- export const MIGRATIONS: Migration[] = [
37
- {
38
- type: MIGRATION_TYPES.GLOBAL,
39
- name: "user_email_view_casing",
40
- fn: userEmailViewCasing.run,
41
- },
42
- {
43
- type: MIGRATION_TYPES.GLOBAL,
44
- name: "quotas_1",
45
- fn: quota1.run,
46
- },
47
- {
48
- type: MIGRATION_TYPES.APP,
49
- name: "app_urls",
50
- opts: { all: true },
51
- fn: appUrls.run,
52
- },
53
- {
54
- type: MIGRATION_TYPES.GLOBAL,
55
- name: "developer_quota",
56
- fn: developerQuota.run,
57
- },
58
- {
59
- type: MIGRATION_TYPES.GLOBAL,
60
- name: "published_apps_quota",
61
- fn: publishedAppsQuota.run,
62
- },
63
- ]
93
+ export const MIGRATIONS = buildMigrations()
64
94
 
65
95
  export const migrate = async (options?: MigrationOptions) => {
66
- await runMigrations(MIGRATIONS, options)
96
+ if (env.SELF_HOSTED) {
97
+ // self host runs migrations on startup
98
+ // make sure only a single instance runs them
99
+ await migrateWithLock(options)
100
+ } else {
101
+ await migrations.runMigrations(MIGRATIONS, options)
102
+ }
103
+ }
104
+
105
+ const migrateWithLock = async (options?: MigrationOptions) => {
106
+ // get a new lock client
107
+
108
+ const redlock = await redis.clients.getMigrationsRedlock()
109
+ // lock for 15 minutes
110
+ const ttl = 1000 * 60 * 15
111
+
112
+ let migrationLock
113
+
114
+ // acquire lock
115
+ try {
116
+ migrationLock = await redlock.lock("migrations", ttl)
117
+ } catch (e: any) {
118
+ if (e.name === "LockError") {
119
+ return
120
+ } else {
121
+ throw e
122
+ }
123
+ }
124
+
125
+ // run migrations
126
+ try {
127
+ await migrations.runMigrations(MIGRATIONS, options)
128
+ } finally {
129
+ // release lock
130
+ try {
131
+ await migrationLock.unlock()
132
+ } catch (e) {
133
+ console.error("unable to release migration lock")
134
+ }
135
+ }
67
136
  }
@@ -0,0 +1,40 @@
1
+ // Mimic configs test configuration from worker, creation configs directly in database
2
+
3
+ import * as structures from "./structures"
4
+ import { db } from "@budibase/backend-core"
5
+ import { Config } from "@budibase/types"
6
+
7
+ export const saveSettingsConfig = async (globalDb: any) => {
8
+ const config = structures.settings()
9
+ await saveConfig(config, globalDb)
10
+ }
11
+
12
+ export const saveGoogleConfig = async (globalDb: any) => {
13
+ const config = structures.google()
14
+ await saveConfig(config, globalDb)
15
+ }
16
+
17
+ export const saveOIDCConfig = async (globalDb: any) => {
18
+ const config = structures.oidc()
19
+ await saveConfig(config, globalDb)
20
+ }
21
+
22
+ export const saveSmtpConfig = async (globalDb: any) => {
23
+ const config = structures.smtp()
24
+ await saveConfig(config, globalDb)
25
+ }
26
+
27
+ const saveConfig = async (config: Config, globalDb: any) => {
28
+ config._id = db.generateConfigID({ type: config.type })
29
+
30
+ let response
31
+ try {
32
+ response = await globalDb.get(config._id)
33
+ config._rev = response._rev
34
+ await globalDb.put(config)
35
+ } catch (e: any) {
36
+ if (e.status === 404) {
37
+ await globalDb.put(config)
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,132 @@
1
+ import {
2
+ events,
3
+ migrations,
4
+ tenancy,
5
+ DocumentTypes,
6
+ context,
7
+ db,
8
+ } from "@budibase/backend-core"
9
+ import TestConfig from "../../tests/utilities/TestConfiguration"
10
+ import structures from "../../tests/utilities/structures"
11
+ import { MIGRATIONS } from "../"
12
+ import * as helpers from "./helpers"
13
+
14
+ const { mocks } = require("@budibase/backend-core/tests")
15
+ const timestamp = mocks.date.MOCK_DATE.toISOString()
16
+
17
+ const clearMigrations = async () => {
18
+ const dbs = [context.getDevAppDB(), context.getProdAppDB()]
19
+ for (const db of dbs) {
20
+ const doc = await db.get(DocumentTypes.MIGRATIONS)
21
+ const newDoc = { _id: doc._id, _rev: doc._rev }
22
+ await db.put(newDoc)
23
+ }
24
+ }
25
+
26
+ describe("migrations", () => {
27
+ const config = new TestConfig()
28
+
29
+ beforeAll(async () => {
30
+ await config.init()
31
+ })
32
+
33
+ afterAll(() => {
34
+ config.end()
35
+ })
36
+
37
+ describe("backfill", () => {
38
+ it("runs app db migration", async () => {
39
+ await config.doInContext(null, async () => {
40
+ await clearMigrations()
41
+ await config.createAutomation()
42
+ await config.createAutomation(structures.newAutomation())
43
+ await config.createDatasource()
44
+ await config.createDatasource()
45
+ await config.createLayout()
46
+ await config.createQuery()
47
+ await config.createQuery()
48
+ await config.createRole()
49
+ await config.createRole()
50
+ await config.createTable()
51
+ await config.createView()
52
+ await config.createTable()
53
+ await config.createView(structures.view(config.table._id))
54
+ await config.createScreen()
55
+ await config.createScreen()
56
+
57
+ jest.clearAllMocks()
58
+ const migration = MIGRATIONS.filter(
59
+ m => m.name === "event_app_backfill"
60
+ )[0]
61
+ await migrations.runMigration(migration)
62
+
63
+ expect(events.app.created).toBeCalledTimes(1)
64
+ expect(events.app.published).toBeCalledTimes(1)
65
+ expect(events.automation.created).toBeCalledTimes(2)
66
+ expect(events.automation.stepCreated).toBeCalledTimes(1)
67
+ expect(events.datasource.created).toBeCalledTimes(2)
68
+ expect(events.layout.created).toBeCalledTimes(1)
69
+ expect(events.query.created).toBeCalledTimes(2)
70
+ expect(events.role.created).toBeCalledTimes(2)
71
+ expect(events.table.created).toBeCalledTimes(3)
72
+ expect(events.view.created).toBeCalledTimes(2)
73
+ expect(events.view.calculationCreated).toBeCalledTimes(1)
74
+ expect(events.view.filterCreated).toBeCalledTimes(1)
75
+ expect(events.screen.created).toBeCalledTimes(2)
76
+ expect(events.backfill.appSucceeded).toBeCalledTimes(2)
77
+
78
+ const processor = events.processors.analyticsProcessor.processEvent
79
+ console.log(processor)
80
+
81
+ // to make sure caching is working as expected
82
+ expect(
83
+ events.processors.analyticsProcessor.processEvent
84
+ ).toBeCalledTimes(23)
85
+ })
86
+ })
87
+ })
88
+
89
+ it("runs global db migration", async () => {
90
+ await config.doInContext(null, async () => {
91
+ await clearMigrations()
92
+ const appId = config.prodAppId
93
+ const roles = { [appId]: "role_12345" }
94
+ await config.createUser(undefined, undefined, false, true, roles) // admin only
95
+ await config.createUser(undefined, undefined, false, false, roles) // non admin non builder
96
+ await config.createTable()
97
+ await config.createRow()
98
+ await config.createRow()
99
+
100
+ const db = tenancy.getGlobalDB()
101
+ await helpers.saveGoogleConfig(db)
102
+ await helpers.saveOIDCConfig(db)
103
+ await helpers.saveSettingsConfig(db)
104
+ await helpers.saveSmtpConfig(db)
105
+
106
+ jest.clearAllMocks()
107
+ const migration = MIGRATIONS.filter(
108
+ m => m.name === "event_global_backfill"
109
+ )[0]
110
+ await migrations.runMigration(migration)
111
+
112
+ expect(events.user.created).toBeCalledTimes(3)
113
+ expect(events.role.assigned).toBeCalledTimes(2)
114
+ expect(events.user.permissionBuilderAssigned).toBeCalledTimes(1) // default test user
115
+ expect(events.user.permissionAdminAssigned).toBeCalledTimes(1) // admin from above
116
+ expect(events.rows.created).toBeCalledTimes(1)
117
+ expect(events.rows.created).toBeCalledWith(2, timestamp)
118
+ expect(events.email.SMTPCreated).toBeCalledTimes(1)
119
+ expect(events.auth.SSOCreated).toBeCalledTimes(2)
120
+ expect(events.auth.SSOActivated).toBeCalledTimes(2)
121
+ expect(events.org.logoUpdated).toBeCalledTimes(1)
122
+ expect(events.org.nameUpdated).toBeCalledTimes(1)
123
+ expect(events.org.platformURLUpdated).toBeCalledTimes(1)
124
+ expect(events.backfill.tenantSucceeded).toBeCalledTimes(1)
125
+
126
+ // to make sure caching is working as expected
127
+ expect(events.processors.analyticsProcessor.processEvent).toBeCalledTimes(
128
+ 19
129
+ )
130
+ })
131
+ })
132
+ })
@@ -0,0 +1,66 @@
1
+ import { utils } from "@budibase/backend-core"
2
+ import {
3
+ SMTPConfig,
4
+ OIDCConfig,
5
+ GoogleConfig,
6
+ SettingsConfig,
7
+ ConfigType,
8
+ } from "@budibase/types"
9
+
10
+ export const oidc = (conf?: OIDCConfig): OIDCConfig => {
11
+ return {
12
+ type: ConfigType.OIDC,
13
+ config: {
14
+ configs: [
15
+ {
16
+ configUrl: "http://someconfigurl",
17
+ clientID: "clientId",
18
+ clientSecret: "clientSecret",
19
+ logo: "Microsoft",
20
+ name: "Active Directory",
21
+ uuid: utils.newid(),
22
+ activated: true,
23
+ ...conf,
24
+ },
25
+ ],
26
+ },
27
+ }
28
+ }
29
+
30
+ export const google = (conf?: GoogleConfig): GoogleConfig => {
31
+ return {
32
+ type: ConfigType.GOOGLE,
33
+ config: {
34
+ clientID: "clientId",
35
+ clientSecret: "clientSecret",
36
+ activated: true,
37
+ ...conf,
38
+ },
39
+ }
40
+ }
41
+
42
+ export const smtp = (conf?: SMTPConfig): SMTPConfig => {
43
+ return {
44
+ type: ConfigType.SMTP,
45
+ config: {
46
+ port: 12345,
47
+ host: "smtptesthost.com",
48
+ from: "testfrom@test.com",
49
+ subject: "Hello!",
50
+ secure: false,
51
+ ...conf,
52
+ },
53
+ }
54
+ }
55
+
56
+ export const settings = (conf?: SettingsConfig): SettingsConfig => {
57
+ return {
58
+ type: ConfigType.SETTINGS,
59
+ config: {
60
+ platformUrl: "http://mycustomdomain.com",
61
+ logoUrl: "http://mylogourl,com",
62
+ company: "mycompany",
63
+ ...conf,
64
+ },
65
+ }
66
+ }
package/src/module.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- declare module "@budibase/backend-core"
2
1
  declare module "@budibase/backend-core/tenancy"
3
2
  declare module "@budibase/backend-core/db"
4
3
  declare module "@budibase/backend-core/context"