From 94789ff03d953a39463189f453ac1a09cab690f4 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 18 Oct 2024 16:51:23 +0100 Subject: [PATCH 1/4] Adding all feature flags to enum, just so there is a simple reference to see all feature flags that are available. --- packages/backend-core/src/features/features.ts | 6 +++--- packages/types/src/sdk/featureFlag.ts | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/backend-core/src/features/features.ts b/packages/backend-core/src/features/features.ts index e95472a784..39b8558d2a 100644 --- a/packages/backend-core/src/features/features.ts +++ b/packages/backend-core/src/features/features.ts @@ -267,9 +267,9 @@ export class FlagSet, T extends { [key: string]: V }> { // All of the machinery in this file is to make sure that flags have their // default values set correctly and their types flow through the system. export const flags = new FlagSet({ - DEFAULT_VALUES: Flag.boolean(env.isDev()), - AUTOMATION_BRANCHING: Flag.boolean(env.isDev()), - SQS: Flag.boolean(true), + [FeatureFlag.DEFAULT_VALUES]: Flag.boolean(env.isDev()), + [FeatureFlag.AUTOMATION_BRANCHING]: Flag.boolean(env.isDev()), + [FeatureFlag.SQS]: Flag.boolean(true), [FeatureFlag.AI_CUSTOM_CONFIGS]: Flag.boolean(env.isDev()), [FeatureFlag.ENRICHED_RELATIONSHIPS]: Flag.boolean(env.isDev()), [FeatureFlag.TABLES_DEFAULT_ADMIN]: Flag.boolean(env.isDev()), diff --git a/packages/types/src/sdk/featureFlag.ts b/packages/types/src/sdk/featureFlag.ts index e35929efe9..a1033236d7 100644 --- a/packages/types/src/sdk/featureFlag.ts +++ b/packages/types/src/sdk/featureFlag.ts @@ -1,7 +1,10 @@ export enum FeatureFlag { PER_CREATOR_PER_USER_PRICE = "PER_CREATOR_PER_USER_PRICE", PER_CREATOR_PER_USER_PRICE_ALERT = "PER_CREATOR_PER_USER_PRICE_ALERT", + AUTOMATION_BRANCHING = "AUTOMATION_BRANCHING", + SQS = "SQS", AI_CUSTOM_CONFIGS = "AI_CUSTOM_CONFIGS", + DEFAULT_VALUES = "DEFAULT_VALUES", ENRICHED_RELATIONSHIPS = "ENRICHED_RELATIONSHIPS", TABLES_DEFAULT_ADMIN = "TABLES_DEFAULT_ADMIN", } From 87bdd68afaf57aade6bf560f670a3522d68ba3d1 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 18 Oct 2024 17:07:35 +0100 Subject: [PATCH 2/4] Updating to use enum for feature flags across the board. --- .../backend-core/src/db/couch/DatabaseImpl.ts | 3 +- packages/pro | 2 +- .../server/src/api/controllers/table/utils.ts | 31 ++++++++++--------- packages/server/src/automations/actions.ts | 3 +- packages/server/src/sdk/app/rows/search.ts | 5 +-- packages/server/src/sdk/app/tables/getters.ts | 3 +- .../src/utilities/rowProcessor/index.ts | 3 +- .../src/api/controllers/system/environment.ts | 7 +++-- 8 files changed, 33 insertions(+), 24 deletions(-) diff --git a/packages/backend-core/src/db/couch/DatabaseImpl.ts b/packages/backend-core/src/db/couch/DatabaseImpl.ts index 8ca20bf8e1..b807db0ee3 100644 --- a/packages/backend-core/src/db/couch/DatabaseImpl.ts +++ b/packages/backend-core/src/db/couch/DatabaseImpl.ts @@ -10,6 +10,7 @@ import { DatabaseQueryOpts, DBError, Document, + FeatureFlag, isDocument, RowResponse, RowValue, @@ -456,7 +457,7 @@ export class DatabaseImpl implements Database { async destroy() { if ( - (await flags.isEnabled("SQS")) && + (await flags.isEnabled(FeatureFlag.SQS)) && (await this.exists(SQLITE_DESIGN_DOC_ID)) ) { // delete the design document, then run the cleanup operation diff --git a/packages/pro b/packages/pro index fc4c7f4925..cad8edfba8 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit fc4c7f4925139af078480217965c3d6338dc0a7f +Subproject commit cad8edfba856058cd12dd9e7363b998ddea76034 diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 106d0e23a6..96c01a15b8 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -1,34 +1,35 @@ -import { parse, isSchema, isRows } from "../../../utilities/schema" -import { getRowParams, generateRowID, InternalTables } from "../../../db/utils" +import { isRows, isSchema, parse } from "../../../utilities/schema" +import { generateRowID, getRowParams, InternalTables } from "../../../db/utils" import isEqual from "lodash/isEqual" import { - GOOGLE_SHEETS_PRIMARY_KEY, - USERS_TABLE_SCHEMA, - SwitchableTypes, CanSwitchTypes, + GOOGLE_SHEETS_PRIMARY_KEY, + SwitchableTypes, + USERS_TABLE_SCHEMA, } from "../../../constants" import { - inputProcessing, AttachmentCleanup, + inputProcessing, } from "../../../utilities/rowProcessor" import { getViews, saveView } from "../view/utils" import viewTemplate from "../view/viewBuilder" import { cloneDeep } from "lodash/fp" import { quotas } from "@budibase/pro" -import { events, context, features } from "@budibase/backend-core" +import { context, events, features } from "@budibase/backend-core" import { AutoFieldSubType, + Database, Datasource, + FeatureFlag, + FieldSchema, + FieldType, + NumberFieldMetadata, + RelationshipFieldMetadata, + RenameColumn, Row, SourceName, Table, - Database, - RenameColumn, - NumberFieldMetadata, - FieldSchema, View, - RelationshipFieldMetadata, - FieldType, } from "@budibase/types" import sdk from "../../../sdk" import env from "../../../environment" @@ -329,7 +330,7 @@ class TableSaveFunctions { importRows: this.importRows, userId: this.userId, }) - if (await features.flags.isEnabled("SQS")) { + if (await features.flags.isEnabled(FeatureFlag.SQS)) { await sdk.tables.sqs.addTable(table) } return table @@ -523,7 +524,7 @@ export async function internalTableCleanup(table: Table, rows?: Row[]) { if (rows) { await AttachmentCleanup.tableDelete(table, rows) } - if (await features.flags.isEnabled("SQS")) { + if (await features.flags.isEnabled(FeatureFlag.SQS)) { await sdk.tables.sqs.removeTable(table) } } diff --git a/packages/server/src/automations/actions.ts b/packages/server/src/automations/actions.ts index f78174aa7a..e921e569c9 100644 --- a/packages/server/src/automations/actions.ts +++ b/packages/server/src/automations/actions.ts @@ -26,6 +26,7 @@ import { Hosting, ActionImplementation, AutomationStepDefinition, + FeatureFlag, } from "@budibase/types" import sdk from "../sdk" import { getAutomationPlugin } from "../utilities/fileSystem" @@ -100,7 +101,7 @@ if (env.SELF_HOSTED) { } export async function getActionDefinitions() { - if (await features.flags.isEnabled("AUTOMATION_BRANCHING")) { + if (await features.flags.isEnabled(FeatureFlag.AUTOMATION_BRANCHING)) { BUILTIN_ACTION_DEFINITIONS["BRANCH"] = branch.definition } const actionDefinitions = BUILTIN_ACTION_DEFINITIONS diff --git a/packages/server/src/sdk/app/rows/search.ts b/packages/server/src/sdk/app/rows/search.ts index 7ac3bb8ead..f80c1c1f8a 100644 --- a/packages/server/src/sdk/app/rows/search.ts +++ b/packages/server/src/sdk/app/rows/search.ts @@ -1,5 +1,6 @@ import { EmptyFilterOption, + FeatureFlag, LegacyFilter, LogicalOperator, Row, @@ -101,7 +102,7 @@ export async function search( viewQuery = checkFilters(table, viewQuery) delete viewQuery?.onEmptyFilter - const sqsEnabled = await features.flags.isEnabled("SQS") + const sqsEnabled = await features.flags.isEnabled(FeatureFlag.SQS) const supportsLogicalOperators = isExternalTableID(view.tableId) || sqsEnabled @@ -168,7 +169,7 @@ export async function search( if (isExternalTable) { span?.addTags({ searchType: "external" }) result = await external.search(options, source) - } else if (await features.flags.isEnabled("SQS")) { + } else if (await features.flags.isEnabled(FeatureFlag.SQS)) { span?.addTags({ searchType: "sqs" }) result = await internal.sqs.search(options, source) } else { diff --git a/packages/server/src/sdk/app/tables/getters.ts b/packages/server/src/sdk/app/tables/getters.ts index 49944bce85..7b3d6913cf 100644 --- a/packages/server/src/sdk/app/tables/getters.ts +++ b/packages/server/src/sdk/app/tables/getters.ts @@ -12,6 +12,7 @@ import { TableResponse, TableSourceType, TableViewsResponse, + FeatureFlag, } from "@budibase/types" import datasources from "../datasources" import sdk from "../../../sdk" @@ -39,7 +40,7 @@ export async function processTable(table: Table): Promise { sourceId: table.sourceId || INTERNAL_TABLE_SOURCE_ID, sourceType: TableSourceType.INTERNAL, } - const sqsEnabled = await features.flags.isEnabled("SQS") + const sqsEnabled = await features.flags.isEnabled(FeatureFlag.SQS) if (sqsEnabled) { processed.sql = true } diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index dd17bc9ba6..6872924f58 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -19,6 +19,7 @@ import { Table, User, ViewV2, + FeatureFlag, } from "@budibase/types" import { cloneDeep } from "lodash/fp" import { @@ -417,7 +418,7 @@ export async function coreOutputProcessing( // remove null properties to match internal API const isExternal = isExternalTableID(table._id!) - if (isExternal || (await features.flags.isEnabled("SQS"))) { + if (isExternal || (await features.flags.isEnabled(FeatureFlag.SQS))) { for (const row of rows) { for (const key of Object.keys(row)) { if (row[key] === null) { diff --git a/packages/worker/src/api/controllers/system/environment.ts b/packages/worker/src/api/controllers/system/environment.ts index 90f303d3a8..b6352ea5e7 100644 --- a/packages/worker/src/api/controllers/system/environment.ts +++ b/packages/worker/src/api/controllers/system/environment.ts @@ -1,4 +1,4 @@ -import { Ctx, MaintenanceType } from "@budibase/types" +import { Ctx, MaintenanceType, FeatureFlag } from "@budibase/types" import env from "../../../environment" import { env as coreEnv, db as dbCore, features } from "@budibase/backend-core" import nodeFetch from "node-fetch" @@ -29,7 +29,10 @@ async function isSqsAvailable() { } async function isSqsMissing() { - return (await features.flags.isEnabled("SQS")) && !(await isSqsAvailable()) + return ( + (await features.flags.isEnabled(FeatureFlag.SQS)) && + !(await isSqsAvailable()) + ) } export const fetch = async (ctx: Ctx) => { From aaa4e7b8dec03ceb3e1e47e9d25ef21abb1d8acf Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 18 Oct 2024 18:31:06 +0100 Subject: [PATCH 3/4] Pro to master. --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index cad8edfba8..297fdc937e 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit cad8edfba856058cd12dd9e7363b998ddea76034 +Subproject commit 297fdc937e9c650b4964fc1a942b60022b195865 From f857e2a3e97c917aad958ff4498f2214825c6f4a Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 21 Oct 2024 12:56:59 +0100 Subject: [PATCH 4/4] Adding BUDIBASE_AI feature flag. --- packages/backend-core/src/features/features.ts | 1 + packages/types/src/sdk/featureFlag.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/backend-core/src/features/features.ts b/packages/backend-core/src/features/features.ts index 39b8558d2a..e2f8d9b6a1 100644 --- a/packages/backend-core/src/features/features.ts +++ b/packages/backend-core/src/features/features.ts @@ -273,6 +273,7 @@ export const flags = new FlagSet({ [FeatureFlag.AI_CUSTOM_CONFIGS]: Flag.boolean(env.isDev()), [FeatureFlag.ENRICHED_RELATIONSHIPS]: Flag.boolean(env.isDev()), [FeatureFlag.TABLES_DEFAULT_ADMIN]: Flag.boolean(env.isDev()), + [FeatureFlag.BUDIBASE_AI]: Flag.boolean(env.isDev()), }) type UnwrapPromise = T extends Promise ? U : T diff --git a/packages/types/src/sdk/featureFlag.ts b/packages/types/src/sdk/featureFlag.ts index a1033236d7..99ee0f9996 100644 --- a/packages/types/src/sdk/featureFlag.ts +++ b/packages/types/src/sdk/featureFlag.ts @@ -7,6 +7,7 @@ export enum FeatureFlag { DEFAULT_VALUES = "DEFAULT_VALUES", ENRICHED_RELATIONSHIPS = "ENRICHED_RELATIONSHIPS", TABLES_DEFAULT_ADMIN = "TABLES_DEFAULT_ADMIN", + BUDIBASE_AI = "BUDIBASE_AI", } export interface TenantFeatureFlags {