@budibase/worker 3.2.46 → 3.3.0
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/package.json +2 -2
- package/src/api/controllers/global/users.ts +0 -6
- package/src/api/routes/index.ts +0 -2
- package/src/tests/api/index.ts +0 -3
- package/src/api/controllers/system/migrations.ts +0 -23
- package/src/api/routes/system/migrations.ts +0 -19
- package/src/api/routes/system/tests/migrations.spec.ts +0 -63
- package/src/migrations/index.ts +0 -62
- package/src/tests/api/migrations.ts +0 -17
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.3.0",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -114,5 +114,5 @@
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
},
|
|
117
|
-
"gitHead": "
|
|
117
|
+
"gitHead": "0bf13accc06044438d403b43ffa9eb696ecabe78"
|
|
118
118
|
}
|
|
@@ -28,7 +28,6 @@ import {
|
|
|
28
28
|
LockType,
|
|
29
29
|
LookupAccountHolderResponse,
|
|
30
30
|
LookupTenantUserResponse,
|
|
31
|
-
MigrationType,
|
|
32
31
|
PlatformUserByEmail,
|
|
33
32
|
SaveUserResponse,
|
|
34
33
|
SearchUsersRequest,
|
|
@@ -45,7 +44,6 @@ import {
|
|
|
45
44
|
cache,
|
|
46
45
|
ErrorCode,
|
|
47
46
|
events,
|
|
48
|
-
migrations,
|
|
49
47
|
platform,
|
|
50
48
|
tenancy,
|
|
51
49
|
db,
|
|
@@ -187,10 +185,6 @@ export const adminUser = async (
|
|
|
187
185
|
if (env.MULTI_TENANCY) {
|
|
188
186
|
// store the new tenant record in the platform db
|
|
189
187
|
await platform.tenants.addTenant(tenantId)
|
|
190
|
-
await migrations.backPopulateMigrations({
|
|
191
|
-
type: MigrationType.GLOBAL,
|
|
192
|
-
tenantId,
|
|
193
|
-
})
|
|
194
188
|
}
|
|
195
189
|
|
|
196
190
|
await tenancy.doInTenant(tenantId, async () => {
|
package/src/api/routes/index.ts
CHANGED
|
@@ -12,7 +12,6 @@ import tenantsRoutes from "./system/tenants"
|
|
|
12
12
|
import statusRoutes from "./system/status"
|
|
13
13
|
import selfRoutes from "./global/self"
|
|
14
14
|
import licenseRoutes from "./global/license"
|
|
15
|
-
import migrationRoutes from "./system/migrations"
|
|
16
15
|
import accountRoutes from "./system/accounts"
|
|
17
16
|
import restoreRoutes from "./system/restore"
|
|
18
17
|
import systemLogRoutes from "./system/logs"
|
|
@@ -34,7 +33,6 @@ export const routes: Router[] = [
|
|
|
34
33
|
licenseRoutes,
|
|
35
34
|
pro.groups,
|
|
36
35
|
pro.auditLogs,
|
|
37
|
-
migrationRoutes,
|
|
38
36
|
accountRoutes,
|
|
39
37
|
restoreRoutes,
|
|
40
38
|
eventRoutes,
|
package/src/tests/api/index.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { EmailAPI } from "./email"
|
|
|
6
6
|
import { SelfAPI } from "./self"
|
|
7
7
|
import { UserAPI } from "./users"
|
|
8
8
|
import { EnvironmentAPI } from "./environment"
|
|
9
|
-
import { MigrationAPI } from "./migrations"
|
|
10
9
|
import { StatusAPI } from "./status"
|
|
11
10
|
import { RestoreAPI } from "./restore"
|
|
12
11
|
import { TenantAPI } from "./tenants"
|
|
@@ -26,7 +25,6 @@ export default class API {
|
|
|
26
25
|
self: SelfAPI
|
|
27
26
|
users: UserAPI
|
|
28
27
|
environment: EnvironmentAPI
|
|
29
|
-
migrations: MigrationAPI
|
|
30
28
|
status: StatusAPI
|
|
31
29
|
restore: RestoreAPI
|
|
32
30
|
tenants: TenantAPI
|
|
@@ -46,7 +44,6 @@ export default class API {
|
|
|
46
44
|
this.self = new SelfAPI(config)
|
|
47
45
|
this.users = new UserAPI(config)
|
|
48
46
|
this.environment = new EnvironmentAPI(config)
|
|
49
|
-
this.migrations = new MigrationAPI(config)
|
|
50
47
|
this.status = new StatusAPI(config)
|
|
51
48
|
this.restore = new RestoreAPI(config)
|
|
52
49
|
this.tenants = new TenantAPI(config)
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FetchMigrationDefinitionsResponse,
|
|
3
|
-
RunGlobalMigrationRequest,
|
|
4
|
-
RunGlobalMigrationResponse,
|
|
5
|
-
UserCtx,
|
|
6
|
-
} from "@budibase/types"
|
|
7
|
-
|
|
8
|
-
const { migrate, MIGRATIONS } = require("../../../migrations")
|
|
9
|
-
|
|
10
|
-
export const runMigrations = async (
|
|
11
|
-
ctx: UserCtx<RunGlobalMigrationRequest, RunGlobalMigrationResponse>
|
|
12
|
-
) => {
|
|
13
|
-
const options = ctx.request.body
|
|
14
|
-
// don't await as can take a while, just return
|
|
15
|
-
migrate(options)
|
|
16
|
-
ctx.body = { message: "Migration started." }
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const fetchDefinitions = async (
|
|
20
|
-
ctx: UserCtx<void, FetchMigrationDefinitionsResponse>
|
|
21
|
-
) => {
|
|
22
|
-
ctx.body = MIGRATIONS
|
|
23
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import Router from "@koa/router"
|
|
2
|
-
import * as migrationsController from "../../controllers/system/migrations"
|
|
3
|
-
import { auth } from "@budibase/backend-core"
|
|
4
|
-
|
|
5
|
-
const router: Router = new Router()
|
|
6
|
-
|
|
7
|
-
router
|
|
8
|
-
.post(
|
|
9
|
-
"/api/system/migrations/run",
|
|
10
|
-
auth.internalApi,
|
|
11
|
-
migrationsController.runMigrations
|
|
12
|
-
)
|
|
13
|
-
.get(
|
|
14
|
-
"/api/system/migrations/definitions",
|
|
15
|
-
auth.internalApi,
|
|
16
|
-
migrationsController.fetchDefinitions
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
export default router
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const migrateFn = jest.fn()
|
|
2
|
-
|
|
3
|
-
import { TestConfiguration } from "../../../../tests"
|
|
4
|
-
|
|
5
|
-
jest.mock("../../../../migrations", () => {
|
|
6
|
-
return {
|
|
7
|
-
...jest.requireActual("../../../../migrations"),
|
|
8
|
-
migrate: migrateFn,
|
|
9
|
-
}
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
describe("/api/system/migrations", () => {
|
|
13
|
-
const config = new TestConfiguration()
|
|
14
|
-
|
|
15
|
-
beforeAll(async () => {
|
|
16
|
-
await config.beforeAll()
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
afterAll(async () => {
|
|
20
|
-
await config.afterAll()
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
afterEach(() => {
|
|
24
|
-
jest.clearAllMocks()
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
describe("POST /api/system/migrations/run", () => {
|
|
28
|
-
it("fails with no internal api key", async () => {
|
|
29
|
-
const res = await config.api.migrations.runMigrations({
|
|
30
|
-
headers: {},
|
|
31
|
-
status: 403,
|
|
32
|
-
})
|
|
33
|
-
expect(res.body).toEqual({ message: "Unauthorized", status: 403 })
|
|
34
|
-
expect(migrateFn).toHaveBeenCalledTimes(0)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it("runs migrations", async () => {
|
|
38
|
-
const res = await config.api.migrations.runMigrations()
|
|
39
|
-
expect(res.body.message).toBeDefined()
|
|
40
|
-
expect(migrateFn).toHaveBeenCalledTimes(1)
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe("DELETE /api/system/migrations/definitions", () => {
|
|
45
|
-
it("fails with no internal api key", async () => {
|
|
46
|
-
const res = await config.api.migrations.getMigrationDefinitions({
|
|
47
|
-
headers: {},
|
|
48
|
-
status: 403,
|
|
49
|
-
})
|
|
50
|
-
expect(res.body).toEqual({ message: "Unauthorized", status: 403 })
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it("returns definitions", async () => {
|
|
54
|
-
const res = await config.api.migrations.getMigrationDefinitions()
|
|
55
|
-
expect(res.body).toEqual([
|
|
56
|
-
{
|
|
57
|
-
name: "global_info_sync_users",
|
|
58
|
-
type: "global",
|
|
59
|
-
},
|
|
60
|
-
])
|
|
61
|
-
})
|
|
62
|
-
})
|
|
63
|
-
})
|
package/src/migrations/index.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { migrations, locks } from "@budibase/backend-core"
|
|
2
|
-
import {
|
|
3
|
-
Migration,
|
|
4
|
-
MigrationOptions,
|
|
5
|
-
MigrationName,
|
|
6
|
-
LockType,
|
|
7
|
-
LockName,
|
|
8
|
-
} from "@budibase/types"
|
|
9
|
-
import env from "../environment"
|
|
10
|
-
|
|
11
|
-
// migration functions
|
|
12
|
-
import * as syncUserInfo from "./functions/globalInfoSyncUsers"
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Populate the migration function and additional configuration from
|
|
16
|
-
* the static migration definitions.
|
|
17
|
-
*/
|
|
18
|
-
export const buildMigrations = () => {
|
|
19
|
-
const definitions = migrations.DEFINITIONS
|
|
20
|
-
const workerMigrations: Migration[] = []
|
|
21
|
-
|
|
22
|
-
for (const definition of definitions) {
|
|
23
|
-
switch (definition.name) {
|
|
24
|
-
case MigrationName.GLOBAL_INFO_SYNC_USERS: {
|
|
25
|
-
// only needed in cloud
|
|
26
|
-
if (!env.SELF_HOSTED) {
|
|
27
|
-
workerMigrations.push({
|
|
28
|
-
...definition,
|
|
29
|
-
fn: syncUserInfo.run,
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
break
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return workerMigrations
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const MIGRATIONS = buildMigrations()
|
|
41
|
-
|
|
42
|
-
export const migrate = async (options?: MigrationOptions) => {
|
|
43
|
-
if (env.SELF_HOSTED) {
|
|
44
|
-
await migrateWithLock(options)
|
|
45
|
-
} else {
|
|
46
|
-
await migrations.runMigrations(MIGRATIONS, options)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const migrateWithLock = async (options?: MigrationOptions) => {
|
|
51
|
-
await locks.doWithLock(
|
|
52
|
-
{
|
|
53
|
-
type: LockType.TRY_ONCE,
|
|
54
|
-
name: LockName.MIGRATIONS,
|
|
55
|
-
ttl: 1000 * 60 * 15, // auto expire the migration lock after 15 minutes
|
|
56
|
-
systemLock: true,
|
|
57
|
-
},
|
|
58
|
-
async () => {
|
|
59
|
-
await migrations.runMigrations(MIGRATIONS, options)
|
|
60
|
-
}
|
|
61
|
-
)
|
|
62
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { TestAPI, TestAPIOpts } from "./base"
|
|
2
|
-
|
|
3
|
-
export class MigrationAPI extends TestAPI {
|
|
4
|
-
runMigrations = (opts?: TestAPIOpts) => {
|
|
5
|
-
return this.request
|
|
6
|
-
.post(`/api/system/migrations/run`)
|
|
7
|
-
.set(opts?.headers ? opts.headers : this.config.internalAPIHeaders())
|
|
8
|
-
.expect(opts?.status ? opts.status : 200)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
getMigrationDefinitions = (opts?: TestAPIOpts) => {
|
|
12
|
-
return this.request
|
|
13
|
-
.get(`/api/system/migrations/definitions`)
|
|
14
|
-
.set(opts?.headers ? opts.headers : this.config.internalAPIHeaders())
|
|
15
|
-
.expect(opts?.status ? opts.status : 200)
|
|
16
|
-
}
|
|
17
|
-
}
|