diff --git a/packages/server/src/sdk/app/datasources/plus.ts b/packages/server/src/sdk/app/datasources/plus.ts index 31ec51c728..a8a21e6906 100644 --- a/packages/server/src/sdk/app/datasources/plus.ts +++ b/packages/server/src/sdk/app/datasources/plus.ts @@ -9,6 +9,7 @@ import * as datasources from "./datasources" import tableSdk from "../tables" import { getIntegration } from "../../../integrations" import { context } from "@budibase/backend-core" +import sdk from "../.." function checkForSchemaErrors(schema: Record) { const errors: Record = {} @@ -96,6 +97,15 @@ export async function buildSchemaFromSource( const datasource = await datasources.get(datasourceId) const { tables, errors } = await buildFilteredSchema(datasource, tablesFilter) + + const oldTables = datasource.entities || {} + const tablesToRemove = Object.keys(oldTables).filter( + t => !Object.keys(tables).includes(t) + ) + for (const table of tablesToRemove) { + await sdk.rowActions.deleteAll(oldTables[table]._id!) + } + datasource.entities = tables datasources.setDefaultDisplayColumns(datasource)