diff --git a/packages/server/src/api/controllers/application.ts b/packages/server/src/api/controllers/application.ts index 660d35c29d..b8f523c331 100644 --- a/packages/server/src/api/controllers/application.ts +++ b/packages/server/src/api/controllers/application.ts @@ -271,6 +271,7 @@ async function performAppCreate(ctx: UserCtx) { path: ctx.request.body.file?.path, } } + const tenantId = tenancy.isMultiTenant() ? tenancy.getTenantId() : null const appId = generateDevAppID(generateAppID(tenantId)) @@ -278,7 +279,7 @@ async function performAppCreate(ctx: UserCtx) { const instance = await createInstance(appId, instanceConfig) const db = context.getAppDB() - let newApplication: App = { + const newApplication: App = { _id: DocumentType.APP_METADATA, _rev: undefined, appId, @@ -309,12 +310,18 @@ async function performAppCreate(ctx: UserCtx) { disableUserMetadata: true, skeletonLoader: true, }, + creationVersion: undefined, } + const isImport = !!instanceConfig.file + if (!isImport) { + newApplication.creationVersion = envCore.VERSION + } + + const existing = await sdk.appMetadata.tryGet() // If we used a template or imported an app there will be an existing doc. // Fetch and migrate some metadata from the existing app. - try { - const existing = await sdk.appMetadata.get() + if (existing) { const keys: (keyof App)[] = [ "_rev", "navigation", @@ -322,6 +329,7 @@ async function performAppCreate(ctx: UserCtx) { "customTheme", "icon", "snippets", + "creationVersion", ] keys.forEach(key => { if (existing[key]) { @@ -339,14 +347,10 @@ async function performAppCreate(ctx: UserCtx) { } // Migrate navigation settings and screens if required - if (existing) { - const navigation = await migrateAppNavigation() - if (navigation) { - newApplication.navigation = navigation - } + const navigation = await migrateAppNavigation() + if (navigation) { + newApplication.navigation = navigation } - } catch (err) { - // Nothing to do } const response = await db.put(newApplication, { force: true }) diff --git a/packages/server/src/sdk/app/appMetadata/metadata.ts b/packages/server/src/sdk/app/appMetadata/metadata.ts index 78d2a040b9..bbda55c085 100644 --- a/packages/server/src/sdk/app/appMetadata/metadata.ts +++ b/packages/server/src/sdk/app/appMetadata/metadata.ts @@ -1,8 +1,18 @@ import { context, DocumentType } from "@budibase/backend-core" import { App } from "@budibase/types" +/** + * @deprecated the plan is to get everything using `tryGet` instead, then rename + * `tryGet` to `get`. + */ export async function get() { const db = context.getAppDB() const application = await db.get(DocumentType.APP_METADATA) return application } + +export async function tryGet() { + const db = context.getAppDB() + const application = await db.tryGet(DocumentType.APP_METADATA) + return application +} diff --git a/packages/types/src/documents/app/app.ts b/packages/types/src/documents/app/app.ts index 69bf3489e1..06fca8307c 100644 --- a/packages/types/src/documents/app/app.ts +++ b/packages/types/src/documents/app/app.ts @@ -27,6 +27,7 @@ export interface App extends Document { usedPlugins?: Plugin[] upgradableVersion?: string snippets?: Snippet[] + creationVersion?: string } export interface AppInstance {