@budibase/server 2.0.30-alpha.7 → 2.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mocks__/mongodb.ts +1 -1
- package/builder/assets/{index.b1aa5e8a.js → index.c4b43e7e.js} +283 -287
- package/builder/assets/{index.a6a040bb.css → index.dfa4073c.css} +2 -2
- package/builder/index.html +2 -2
- package/coverage/clover.xml +491 -495
- package/coverage/coverage-final.json +26 -26
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +2 -2
- package/coverage/lcov-report/api/controllers/index.html +1 -1
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +12 -12
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +15 -15
- package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +5 -5
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +5 -5
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -3
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +22 -22
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +2 -8
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +11 -11
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +11 -11
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +3 -3
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +16 -10
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +2 -2
- package/coverage/lcov-report/events/utils.js.html +9 -9
- package/coverage/lcov-report/index.html +24 -24
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/builder.js.html +11 -11
- package/coverage/lcov-report/middleware/currentapp.js.html +34 -34
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +8 -11
- package/coverage/lcov-report/utilities/global.js.html +16 -16
- package/coverage/lcov-report/utilities/index.html +15 -15
- package/coverage/lcov-report/utilities/index.js.html +7 -7
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +13 -13
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +39 -54
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +10 -10
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +1 -1
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +14 -14
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +11 -23
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +892 -900
- package/dist/api/controllers/application.js +2 -2
- package/dist/api/controllers/dev.js +1 -1
- package/dist/api/controllers/query/index.js +2 -7
- package/dist/api/controllers/row/index.js +10 -30
- package/dist/api/controllers/static/templates/preview.hbs +0 -10
- package/dist/api/controllers/table/internal.js +2 -8
- package/dist/api/controllers/table/utils.js +1 -3
- package/dist/automations/steps/updateRow.js +2 -2
- package/dist/automations/utils.js +3 -5
- package/dist/constants/index.js +0 -2
- package/dist/db/utils.js +1 -1
- package/dist/index.js +0 -1
- package/dist/integrations/base/sqlTable.js +0 -1
- package/dist/integrations/mongodb.js +11 -300
- package/dist/integrations/rest.js +5 -38
- package/dist/migrations/functions/{usageQuotas/syncPlugins.js → pluginCount.js} +3 -1
- package/dist/migrations/functions/{syncQuotas.js → quotas1.js} +7 -3
- package/dist/migrations/functions/usageQuotas/syncApps.js +1 -0
- package/dist/migrations/functions/usageQuotas/syncRows.js +5 -9
- package/dist/migrations/index.js +38 -9
- package/dist/package.json +9 -8
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/csvParser.js +0 -1
- package/dist/utilities/rowProcessor/index.js +0 -5
- package/dist/utilities/usageQuota/rows.js +4 -6
- package/package.json +10 -9
- package/specs/openapi.json +0 -3
- package/specs/openapi.yaml +0 -3
- package/src/api/controllers/application.ts +2 -2
- package/src/api/controllers/deploy/index.ts +1 -0
- package/src/api/controllers/dev.js +1 -1
- package/src/api/controllers/query/index.ts +2 -8
- package/src/api/controllers/row/index.ts +13 -36
- package/src/api/controllers/static/templates/preview.hbs +0 -10
- package/src/api/controllers/table/internal.ts +2 -5
- package/src/api/controllers/table/utils.ts +1 -3
- package/src/api/routes/tests/row.spec.js +27 -22
- package/src/automations/steps/updateRow.js +2 -2
- package/src/automations/tests/automation.spec.js +6 -1
- package/src/automations/utils.ts +4 -6
- package/src/constants/index.js +0 -2
- package/src/db/utils.js +2 -0
- package/src/definitions/datasource.ts +0 -1
- package/src/index.ts +0 -1
- package/src/integrations/base/sqlTable.ts +0 -1
- package/src/integrations/mongodb.ts +27 -290
- package/src/integrations/rest.ts +5 -17
- package/src/integrations/tests/mongo.spec.ts +19 -19
- package/src/integrations/tests/rest.spec.ts +22 -38
- package/src/migrations/functions/backfill/global.ts +1 -1
- package/src/migrations/functions/pluginCount.ts +12 -0
- package/src/migrations/functions/{syncQuotas.ts → quotas1.ts} +8 -3
- package/src/migrations/functions/tests/{syncQuotas.spec.js → quotas1.spec.js} +2 -5
- package/src/migrations/functions/usageQuotas/syncApps.ts +1 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +6 -15
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +1 -9
- package/src/migrations/index.ts +45 -20
- package/src/migrations/tests/index.spec.ts +1 -0
- package/src/utilities/csvParser.js +0 -1
- package/src/utilities/rowProcessor/index.js +0 -5
- package/src/utilities/usageQuota/rows.js +3 -7
- package/src/migrations/functions/usageQuotas/syncPlugins.ts +0 -10
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
jest.mock("node-fetch", () =>
|
|
2
|
+
jest.fn(() => ({
|
|
3
|
+
headers: {
|
|
4
|
+
raw: () => {
|
|
5
|
+
return { "content-type": ["application/json"] }
|
|
6
|
+
},
|
|
7
|
+
get: () => ["application/json"],
|
|
5
8
|
},
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}))
|
|
11
|
-
|
|
12
|
-
}))
|
|
13
|
-
jest.mock("node-fetch", () => mockFetch)
|
|
9
|
+
json: jest.fn(() => ({
|
|
10
|
+
my_next_cursor: 123,
|
|
11
|
+
})),
|
|
12
|
+
text: jest.fn(),
|
|
13
|
+
}))
|
|
14
|
+
)
|
|
14
15
|
import fetch from "node-fetch"
|
|
15
16
|
import { default as RestIntegration } from "../rest"
|
|
16
17
|
const FormData = require("form-data")
|
|
@@ -255,7 +256,7 @@ describe("REST Integration", () => {
|
|
|
255
256
|
authConfigId: "c59c14bd1898a43baa08da68959b24686",
|
|
256
257
|
}
|
|
257
258
|
await config.integration.read(query)
|
|
258
|
-
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}
|
|
259
|
+
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
|
259
260
|
method: "GET",
|
|
260
261
|
headers: {
|
|
261
262
|
Authorization: "Basic dXNlcjpwYXNzd29yZA==",
|
|
@@ -268,7 +269,7 @@ describe("REST Integration", () => {
|
|
|
268
269
|
authConfigId: "0d91d732f34e4befabeff50b392a8ff3",
|
|
269
270
|
}
|
|
270
271
|
await config.integration.read(query)
|
|
271
|
-
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}
|
|
272
|
+
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
|
272
273
|
method: "GET",
|
|
273
274
|
headers: {
|
|
274
275
|
Authorization: "Bearer mytoken",
|
|
@@ -326,7 +327,7 @@ describe("REST Integration", () => {
|
|
|
326
327
|
},
|
|
327
328
|
}
|
|
328
329
|
await config.integration.create(query)
|
|
329
|
-
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api
|
|
330
|
+
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
|
330
331
|
body: JSON.stringify({
|
|
331
332
|
[pageParam]: pageValue,
|
|
332
333
|
[sizeParam]: sizeValue,
|
|
@@ -358,7 +359,7 @@ describe("REST Integration", () => {
|
|
|
358
359
|
},
|
|
359
360
|
}
|
|
360
361
|
await config.integration.create(query)
|
|
361
|
-
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api
|
|
362
|
+
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
|
362
363
|
body: expect.any(FormData),
|
|
363
364
|
headers: {},
|
|
364
365
|
method: "POST",
|
|
@@ -389,7 +390,7 @@ describe("REST Integration", () => {
|
|
|
389
390
|
},
|
|
390
391
|
}
|
|
391
392
|
await config.integration.create(query)
|
|
392
|
-
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api
|
|
393
|
+
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
|
393
394
|
body: expect.any(URLSearchParams),
|
|
394
395
|
headers: {},
|
|
395
396
|
method: "POST",
|
|
@@ -455,7 +456,7 @@ describe("REST Integration", () => {
|
|
|
455
456
|
},
|
|
456
457
|
}
|
|
457
458
|
const res = await config.integration.create(query)
|
|
458
|
-
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api
|
|
459
|
+
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
|
459
460
|
body: JSON.stringify({
|
|
460
461
|
[pageParam]: pageValue,
|
|
461
462
|
[sizeParam]: sizeValue,
|
|
@@ -489,7 +490,7 @@ describe("REST Integration", () => {
|
|
|
489
490
|
},
|
|
490
491
|
}
|
|
491
492
|
const res = await config.integration.create(query)
|
|
492
|
-
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api
|
|
493
|
+
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
|
493
494
|
body: expect.any(FormData),
|
|
494
495
|
headers: {},
|
|
495
496
|
method: "POST",
|
|
@@ -522,7 +523,7 @@ describe("REST Integration", () => {
|
|
|
522
523
|
},
|
|
523
524
|
}
|
|
524
525
|
const res = await config.integration.create(query)
|
|
525
|
-
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api
|
|
526
|
+
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, {
|
|
526
527
|
body: expect.any(URLSearchParams),
|
|
527
528
|
headers: {},
|
|
528
529
|
method: "POST",
|
|
@@ -562,7 +563,7 @@ describe("REST Integration", () => {
|
|
|
562
563
|
legacyHttpParser: true,
|
|
563
564
|
})
|
|
564
565
|
await config.integration.read({})
|
|
565
|
-
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}
|
|
566
|
+
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
|
566
567
|
method: "GET",
|
|
567
568
|
headers: {},
|
|
568
569
|
extraHttpOptions: {
|
|
@@ -571,21 +572,4 @@ describe("REST Integration", () => {
|
|
|
571
572
|
})
|
|
572
573
|
})
|
|
573
574
|
})
|
|
574
|
-
|
|
575
|
-
it("Attaches custom agent when Reject Unauthorized option is false", async () => {
|
|
576
|
-
config = new TestConfiguration({
|
|
577
|
-
url: BASE_URL,
|
|
578
|
-
rejectUnauthorized: false,
|
|
579
|
-
})
|
|
580
|
-
await config.integration.read({})
|
|
581
|
-
|
|
582
|
-
const calls: any = mockFetch.mock.calls[0]
|
|
583
|
-
const url = calls[0]
|
|
584
|
-
expect(url).toBe(`${BASE_URL}/`)
|
|
585
|
-
|
|
586
|
-
const calledConfig = calls[1]
|
|
587
|
-
expect(calledConfig.method).toBe("GET")
|
|
588
|
-
expect(calledConfig.headers).toEqual({})
|
|
589
|
-
expect(calledConfig.agent.options.rejectUnauthorized).toBe(false)
|
|
590
|
-
})
|
|
591
575
|
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { tenancy, logging } from "@budibase/backend-core"
|
|
2
|
+
import { plugins } from "@budibase/pro"
|
|
3
|
+
|
|
4
|
+
export const run = async () => {
|
|
5
|
+
try {
|
|
6
|
+
await tenancy.doInTenant(tenancy.DEFAULT_TENANT_ID, async () => {
|
|
7
|
+
await plugins.checkPluginQuotas()
|
|
8
|
+
})
|
|
9
|
+
} catch (err) {
|
|
10
|
+
logging.logAlert("Failed to update plugin quotas", err)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { runQuotaMigration } from "./usageQuotas"
|
|
2
2
|
import * as syncApps from "./usageQuotas/syncApps"
|
|
3
3
|
import * as syncRows from "./usageQuotas/syncRows"
|
|
4
|
-
import * as syncPlugins from "./usageQuotas/syncPlugins"
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
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.
|
|
8
13
|
*/
|
|
14
|
+
|
|
9
15
|
export const run = async () => {
|
|
10
16
|
await runQuotaMigration(async () => {
|
|
11
17
|
await syncApps.run()
|
|
12
18
|
await syncRows.run()
|
|
13
|
-
await syncPlugins.run()
|
|
14
19
|
})
|
|
15
20
|
}
|
|
@@ -2,13 +2,11 @@ const TestConfig = require("../../../tests/utilities/TestConfiguration")
|
|
|
2
2
|
|
|
3
3
|
const syncApps = jest.fn()
|
|
4
4
|
const syncRows = jest.fn()
|
|
5
|
-
const syncPlugins = jest.fn()
|
|
6
5
|
|
|
7
6
|
jest.mock("../usageQuotas/syncApps", () => ({ run: syncApps }) )
|
|
8
7
|
jest.mock("../usageQuotas/syncRows", () => ({ run: syncRows }) )
|
|
9
|
-
jest.mock("../usageQuotas/syncPlugins", () => ({ run: syncPlugins }) )
|
|
10
8
|
|
|
11
|
-
const migration = require("../
|
|
9
|
+
const migration = require("../quotas1")
|
|
12
10
|
|
|
13
11
|
describe("run", () => {
|
|
14
12
|
let config = new TestConfig(false)
|
|
@@ -19,10 +17,9 @@ describe("run", () => {
|
|
|
19
17
|
|
|
20
18
|
afterAll(config.end)
|
|
21
19
|
|
|
22
|
-
it("
|
|
20
|
+
it("runs ", async () => {
|
|
23
21
|
await migration.run()
|
|
24
22
|
expect(syncApps).toHaveBeenCalledTimes(1)
|
|
25
23
|
expect(syncRows).toHaveBeenCalledTimes(1)
|
|
26
|
-
expect(syncPlugins).toHaveBeenCalledTimes(1)
|
|
27
24
|
})
|
|
28
25
|
})
|
|
@@ -2,28 +2,19 @@ import { getTenantId } from "@budibase/backend-core/tenancy"
|
|
|
2
2
|
import { getAllApps } from "@budibase/backend-core/db"
|
|
3
3
|
import { getUniqueRows } from "../../../utilities/usageQuota/rows"
|
|
4
4
|
import { quotas } from "@budibase/pro"
|
|
5
|
-
import {
|
|
5
|
+
import { QuotaUsageType, StaticQuotaName } from "@budibase/types"
|
|
6
6
|
|
|
7
7
|
export const run = async () => {
|
|
8
8
|
// get all rows in all apps
|
|
9
|
+
// @ts-ignore
|
|
9
10
|
const allApps = await getAllApps({ all: true })
|
|
11
|
+
// @ts-ignore
|
|
10
12
|
const appIds = allApps ? allApps.map((app: { appId: any }) => app.appId) : []
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
// get the counts per app
|
|
14
|
-
const counts: { [key: string]: number } = {}
|
|
15
|
-
let rowCount = 0
|
|
16
|
-
Object.entries(appRows).forEach(([appId, rows]) => {
|
|
17
|
-
counts[appId] = rows.length
|
|
18
|
-
rowCount += rows.length
|
|
19
|
-
})
|
|
13
|
+
const rows = await getUniqueRows(appIds)
|
|
14
|
+
const rowCount = rows ? rows.length : 0
|
|
20
15
|
|
|
21
16
|
// sync row count
|
|
22
17
|
const tenantId = getTenantId()
|
|
23
18
|
console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`)
|
|
24
|
-
await quotas.
|
|
25
|
-
counts,
|
|
26
|
-
StaticQuotaName.ROWS,
|
|
27
|
-
QuotaUsageType.STATIC
|
|
28
|
-
)
|
|
19
|
+
await quotas.setUsage(rowCount, StaticQuotaName.ROWS, QuotaUsageType.STATIC)
|
|
29
20
|
}
|
|
@@ -2,7 +2,6 @@ import TestConfig from "../../../../tests/utilities/TestConfiguration"
|
|
|
2
2
|
import * as syncRows from "../syncRows"
|
|
3
3
|
import { quotas } from "@budibase/pro"
|
|
4
4
|
import { QuotaUsageType, StaticQuotaName } from "@budibase/types"
|
|
5
|
-
const { getProdAppID } = require("@budibase/backend-core/db")
|
|
6
5
|
|
|
7
6
|
describe("syncRows", () => {
|
|
8
7
|
let config = new TestConfig(false)
|
|
@@ -23,11 +22,10 @@ describe("syncRows", () => {
|
|
|
23
22
|
expect(usageDoc.usageQuota.rows).toEqual(300)
|
|
24
23
|
|
|
25
24
|
// app 1
|
|
26
|
-
const app1 = config.app
|
|
27
25
|
await config.createTable()
|
|
28
26
|
await config.createRow()
|
|
29
27
|
// app 2
|
|
30
|
-
|
|
28
|
+
await config.createApp("second-app")
|
|
31
29
|
await config.createTable()
|
|
32
30
|
await config.createRow()
|
|
33
31
|
await config.createRow()
|
|
@@ -38,12 +36,6 @@ describe("syncRows", () => {
|
|
|
38
36
|
// assert the migration worked
|
|
39
37
|
usageDoc = await quotas.getQuotaUsage()
|
|
40
38
|
expect(usageDoc.usageQuota.rows).toEqual(3)
|
|
41
|
-
expect(usageDoc.apps?.[getProdAppID(app1.appId)].usageQuota.rows).toEqual(
|
|
42
|
-
1
|
|
43
|
-
)
|
|
44
|
-
expect(usageDoc.apps?.[getProdAppID(app2.appId)].usageQuota.rows).toEqual(
|
|
45
|
-
2
|
|
46
|
-
)
|
|
47
39
|
})
|
|
48
40
|
})
|
|
49
41
|
})
|
package/src/migrations/index.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
Migration,
|
|
4
|
-
MigrationOptions,
|
|
5
|
-
MigrationName,
|
|
6
|
-
LockType,
|
|
7
|
-
LockName,
|
|
8
|
-
} from "@budibase/types"
|
|
1
|
+
import { migrations, redis } from "@budibase/backend-core"
|
|
2
|
+
import { Migration, MigrationOptions, MigrationName } from "@budibase/types"
|
|
9
3
|
import env from "../environment"
|
|
10
4
|
|
|
11
5
|
// migration functions
|
|
12
6
|
import * as userEmailViewCasing from "./functions/userEmailViewCasing"
|
|
13
|
-
import * as
|
|
7
|
+
import * as quota1 from "./functions/quotas1"
|
|
14
8
|
import * as appUrls from "./functions/appUrls"
|
|
15
9
|
import * as backfill from "./functions/backfill"
|
|
10
|
+
import * as pluginCount from "./functions/pluginCount"
|
|
11
|
+
|
|
16
12
|
/**
|
|
17
13
|
* Populate the migration function and additional configuration from
|
|
18
14
|
* the static migration definitions.
|
|
@@ -30,10 +26,10 @@ export const buildMigrations = () => {
|
|
|
30
26
|
})
|
|
31
27
|
break
|
|
32
28
|
}
|
|
33
|
-
case MigrationName.
|
|
29
|
+
case MigrationName.QUOTAS_1: {
|
|
34
30
|
serverMigrations.push({
|
|
35
31
|
...definition,
|
|
36
|
-
fn:
|
|
32
|
+
fn: quota1.run,
|
|
37
33
|
})
|
|
38
34
|
break
|
|
39
35
|
}
|
|
@@ -73,6 +69,16 @@ export const buildMigrations = () => {
|
|
|
73
69
|
})
|
|
74
70
|
break
|
|
75
71
|
}
|
|
72
|
+
case MigrationName.PLUGIN_COUNT: {
|
|
73
|
+
if (env.SELF_HOSTED) {
|
|
74
|
+
serverMigrations.push({
|
|
75
|
+
...definition,
|
|
76
|
+
fn: pluginCount.run,
|
|
77
|
+
silent: !!env.SELF_HOSTED,
|
|
78
|
+
preventRetry: false,
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
}
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
|
|
@@ -92,14 +98,33 @@ export const migrate = async (options?: MigrationOptions) => {
|
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
const migrateWithLock = async (options?: MigrationOptions) => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
// get a new lock client
|
|
102
|
+
const redlock = await redis.clients.getMigrationsRedlock()
|
|
103
|
+
// lock for 15 minutes
|
|
104
|
+
const ttl = 1000 * 60 * 15
|
|
105
|
+
|
|
106
|
+
let migrationLock
|
|
107
|
+
|
|
108
|
+
// acquire lock
|
|
109
|
+
try {
|
|
110
|
+
migrationLock = await redlock.lock("migrations", ttl)
|
|
111
|
+
} catch (e: any) {
|
|
112
|
+
if (e.name === "LockError") {
|
|
113
|
+
return
|
|
114
|
+
} else {
|
|
115
|
+
throw e
|
|
103
116
|
}
|
|
104
|
-
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// run migrations
|
|
120
|
+
try {
|
|
121
|
+
await migrations.runMigrations(MIGRATIONS, options)
|
|
122
|
+
} finally {
|
|
123
|
+
// release lock
|
|
124
|
+
try {
|
|
125
|
+
await migrationLock.unlock()
|
|
126
|
+
} catch (e) {
|
|
127
|
+
console.error("unable to release migration lock")
|
|
128
|
+
}
|
|
129
|
+
}
|
|
105
130
|
}
|
|
@@ -2,7 +2,6 @@ const { getRowParams, USER_METDATA_PREFIX } = require("../../db/utils")
|
|
|
2
2
|
const {
|
|
3
3
|
isDevAppID,
|
|
4
4
|
getDevelopmentAppID,
|
|
5
|
-
getProdAppID,
|
|
6
5
|
doWithDB,
|
|
7
6
|
} = require("@budibase/backend-core/db")
|
|
8
7
|
|
|
@@ -53,8 +52,7 @@ const getAppRows = async appId => {
|
|
|
53
52
|
* Rows duplicates may exist across apps due to data import so they are not filtered out.
|
|
54
53
|
*/
|
|
55
54
|
exports.getUniqueRows = async appIds => {
|
|
56
|
-
let uniqueRows = []
|
|
57
|
-
rowsByApp = {}
|
|
55
|
+
let uniqueRows = []
|
|
58
56
|
const pairs = getAppPairs(appIds)
|
|
59
57
|
|
|
60
58
|
for (let pair of Object.values(pairs)) {
|
|
@@ -75,10 +73,8 @@ exports.getUniqueRows = async appIds => {
|
|
|
75
73
|
// this can't be done on all rows because app import results in
|
|
76
74
|
// duplicate row ids across apps
|
|
77
75
|
// the array pre-concat is important to avoid stack overflow
|
|
78
|
-
|
|
79
|
-
rowsByApp[prodId] = [...new Set(appRows)]
|
|
80
|
-
uniqueRows = uniqueRows.concat(rowsByApp[prodId])
|
|
76
|
+
uniqueRows = uniqueRows.concat([...new Set(appRows)])
|
|
81
77
|
}
|
|
82
78
|
|
|
83
|
-
return
|
|
79
|
+
return uniqueRows
|
|
84
80
|
}
|