From d880302553762476e9c4be9c0f4beea6ad19447c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 14 Dec 2023 10:04:10 +0100 Subject: [PATCH 01/15] Check if migrations are needed on app serve --- .../src/api/controllers/static/index.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index 2963546e7f..4828181149 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -25,8 +25,12 @@ import fs from "fs" import sdk from "../../../sdk" import * as pro from "@budibase/pro" import { App, Ctx, ProcessAttachmentResponse } from "@budibase/types" +import { + getAppMigrationVersion, + getLatestMigrationId, +} from "../../../appMigrations" -const send = require("koa-send") +import send from "koa-send" export const toggleBetaUiFeature = async function (ctx: Ctx) { const cookieName = `beta:${ctx.params.feature}` @@ -125,7 +129,21 @@ export const deleteObjects = async function (ctx: Ctx) { ) } +const requiresMigration = async (ctx: Ctx) => { + const appId = context.getAppId() + if (!appId) { + ctx.throw("AppId could not be found") + } + + const latestAppliedMigration = await getAppMigrationVersion(appId) + + const requiresMigrations = latestAppliedMigration !== getLatestMigrationId() + return requiresMigrations +} + export const serveApp = async function (ctx: Ctx) { + const needMigrations = await requiresMigration(ctx) + const bbHeaderEmbed = ctx.request.get("x-budibase-embed")?.toLowerCase() === "true" @@ -273,7 +291,6 @@ export const getSignedUploadURL = async function (ctx: Ctx) { const { bucket, key } = ctx.request.body || {} if (!bucket || !key) { ctx.throw(400, "bucket and key values are required") - return } try { const s3 = new AWS.S3({ From 2cb9f10327324f6d64a2c9a3b68b293e465ef339 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 14 Dec 2023 10:04:22 +0100 Subject: [PATCH 02/15] Nodemon, watch svelte on server --- packages/server/nodemon.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/nodemon.json b/packages/server/nodemon.json index 33d277dd64..5535e0772e 100644 --- a/packages/server/nodemon.json +++ b/packages/server/nodemon.json @@ -7,7 +7,7 @@ "../shared-core", "../string-templates" ], - "ext": "js,ts,json", + "ext": "js,ts,json,svelte", "ignore": ["src/**/*.spec.ts", "src/**/*.spec.js", "../*/dist/**/*"], "exec": "yarn build && node ./dist/index.js" } From 357522ec6e419636a3829eaad78326dca1527ce3 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 18 Dec 2023 16:15:00 +0100 Subject: [PATCH 03/15] Server render updating page --- packages/server/src/api/controllers/static/index.ts | 6 ++++-- .../src/api/controllers/static/templates/Updating.svelte | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 packages/server/src/api/controllers/static/templates/Updating.svelte diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index 4828181149..c23ea349d4 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -156,6 +156,10 @@ export const serveApp = async function (ctx: Ctx) { appHbsPath = join(__dirname, "templates", "app.hbs") } + const App = !needMigrations + ? require("./templates/BudibaseApp.svelte").default + : require("./templates/Updating.svelte").default + let db try { db = context.getAppDB({ skip_setup: true }) @@ -163,7 +167,6 @@ export const serveApp = async function (ctx: Ctx) { let appId = context.getAppId() if (!env.isJest()) { - const App = require("./templates/BudibaseApp.svelte").default const plugins = objectStore.enrichPluginURLs(appInfo.usedPlugins) const { head, html, css } = App.render({ metaImage: @@ -200,7 +203,6 @@ export const serveApp = async function (ctx: Ctx) { } } catch (error) { if (!env.isJest()) { - const App = require("./templates/BudibaseApp.svelte").default const { head, html, css } = App.render({ title: branding?.metaTitle, metaTitle: branding?.metaTitle, diff --git a/packages/server/src/api/controllers/static/templates/Updating.svelte b/packages/server/src/api/controllers/static/templates/Updating.svelte new file mode 100644 index 0000000000..5c7e23b5b3 --- /dev/null +++ b/packages/server/src/api/controllers/static/templates/Updating.svelte @@ -0,0 +1,8 @@ +
Updating the system...
+ + From 0b46b6883df543b6b33206831d04a6817257638c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 19 Dec 2023 10:37:14 +0100 Subject: [PATCH 04/15] Remove unused regexparam --- packages/client/package.json | 1 - yarn.lock | 5 ----- 2 files changed, 6 deletions(-) diff --git a/packages/client/package.json b/packages/client/package.json index 39ddb4bd49..227c7b25d4 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -37,7 +37,6 @@ "downloadjs": "1.4.7", "html5-qrcode": "^2.2.1", "leaflet": "^1.7.1", - "regexparam": "^1.3.0", "sanitize-html": "^2.7.0", "screenfull": "^6.0.1", "shortid": "^2.2.15", diff --git a/yarn.lock b/yarn.lock index 150585ce1a..85dd6ab251 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18312,11 +18312,6 @@ regexparam@2.0.1: resolved "https://registry.yarnpkg.com/regexparam/-/regexparam-2.0.1.tgz#c912f5dae371e3798100b3c9ce22b7414d0889fa" integrity sha512-zRgSaYemnNYxUv+/5SeoHI0eJIgTL/A2pUtXUPLHQxUldagouJ9p+K6IbIZ/JiQuCEv2E2B1O11SjVQy3aMCkw== -regexparam@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/regexparam/-/regexparam-1.3.0.tgz#2fe42c93e32a40eff6235d635e0ffa344b92965f" - integrity sha512-6IQpFBv6e5vz1QAqI+V4k8P2e/3gRrqfCJ9FI+O1FLQTO+Uz6RXZEZOPmTJ6hlGj7gkERzY5BRCv09whKP96/g== - regexpu-core@^5.3.1: version "5.3.1" resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-5.3.1.tgz#66900860f88def39a5cb79ebd9490e84f17bcdfb" From 75b8190c01898b3522ce5605191d6a9211cd09a1 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 19 Dec 2023 12:05:27 +0100 Subject: [PATCH 05/15] Move updating page to the client --- .../src/components/UpdatingApp.svelte} | 3 +++ packages/client/src/index.js | 8 ++++++++ packages/server/src/api/controllers/static/index.ts | 7 +++---- .../api/controllers/static/templates/BudibaseApp.svelte | 6 ++++++ 4 files changed, 20 insertions(+), 4 deletions(-) rename packages/{server/src/api/controllers/static/templates/Updating.svelte => client/src/components/UpdatingApp.svelte} (86%) diff --git a/packages/server/src/api/controllers/static/templates/Updating.svelte b/packages/client/src/components/UpdatingApp.svelte similarity index 86% rename from packages/server/src/api/controllers/static/templates/Updating.svelte rename to packages/client/src/components/UpdatingApp.svelte index 5c7e23b5b3..b24f591c5c 100644 --- a/packages/server/src/api/controllers/static/templates/Updating.svelte +++ b/packages/client/src/components/UpdatingApp.svelte @@ -1,3 +1,6 @@ + +
Updating the system...
From bfaab228d57429df634263d34c1017d3ecbf008a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jan 2024 12:07:26 +0100 Subject: [PATCH 11/15] Use updating page from frontend --- .../client/src/components/UpdatingApp.svelte | 60 +++---------------- 1 file changed, 7 insertions(+), 53 deletions(-) diff --git a/packages/client/src/components/UpdatingApp.svelte b/packages/client/src/components/UpdatingApp.svelte index 7d8d54df45..d93355394e 100644 --- a/packages/client/src/components/UpdatingApp.svelte +++ b/packages/client/src/components/UpdatingApp.svelte @@ -1,61 +1,15 @@ -
- {#if !timedOut} -

- 🛠️ We are updating the system.
Please wait, we will be back in a - second! -

- {:else} -

- An error occurred. Please try again later. -

- {/if} -
- - + From 9ebe93f71d3eade90062ca955292d6ef8f3368d6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jan 2024 12:10:35 +0100 Subject: [PATCH 12/15] Clean --- packages/client/src/components/UpdatingApp.svelte | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/client/src/components/UpdatingApp.svelte b/packages/client/src/components/UpdatingApp.svelte index d93355394e..4177ea017f 100644 --- a/packages/client/src/components/UpdatingApp.svelte +++ b/packages/client/src/components/UpdatingApp.svelte @@ -1,15 +1,9 @@ - + From f77b81267933d2f868b4af188be73b2bbb70a879 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jan 2024 12:15:12 +0100 Subject: [PATCH 13/15] Handle no migrations --- packages/server/src/api/controllers/static/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index 0166f92478..5f383e837d 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -135,9 +135,14 @@ const requiresMigration = async (ctx: Ctx) => { ctx.throw("AppId could not be found") } - const latestAppliedMigration = await getAppMigrationVersion(appId) + const latestMigration = getLatestMigrationId() + if (!latestMigration) { + return false + } - const requiresMigrations = latestAppliedMigration !== getLatestMigrationId() + const latestMigrationApplied = await getAppMigrationVersion(appId) + + const requiresMigrations = latestMigrationApplied !== latestMigration return requiresMigrations } From f123a821bd95add40876b331aeae213e9152238d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jan 2024 12:21:34 +0100 Subject: [PATCH 14/15] Styling --- packages/client/src/components/UpdatingApp.svelte | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/client/src/components/UpdatingApp.svelte b/packages/client/src/components/UpdatingApp.svelte index 4177ea017f..b493b7cd67 100644 --- a/packages/client/src/components/UpdatingApp.svelte +++ b/packages/client/src/components/UpdatingApp.svelte @@ -6,4 +6,12 @@ } - +
+ +
+ + From 2a07aa35f4da73e1447c45708eea967d516b33e5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jan 2024 13:48:50 +0100 Subject: [PATCH 15/15] Pass api call --- packages/client/src/components/UpdatingApp.svelte | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/client/src/components/UpdatingApp.svelte b/packages/client/src/components/UpdatingApp.svelte index b493b7cd67..74e5500715 100644 --- a/packages/client/src/components/UpdatingApp.svelte +++ b/packages/client/src/components/UpdatingApp.svelte @@ -1,5 +1,11 @@
- +