Merge pull request #15518 from Budibase/fix/ds-deletion-pre-empt
DS+ deletion - fix issue with incorrectly detecting as table
This commit is contained in:
commit
248ddbb0fc
|
@ -8,6 +8,10 @@ import {
|
||||||
import { getProdAppID } from "./conversions"
|
import { getProdAppID } from "./conversions"
|
||||||
import { DatabaseQueryOpts, VirtualDocumentType } from "@budibase/types"
|
import { DatabaseQueryOpts, VirtualDocumentType } from "@budibase/types"
|
||||||
|
|
||||||
|
const EXTERNAL_TABLE_ID_REGEX = new RegExp(
|
||||||
|
`^${DocumentType.DATASOURCE_PLUS}_(.+)__(.+)$`
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If creating DB allDocs/query params with only a single top level ID this can be used, this
|
* If creating DB allDocs/query params with only a single top level ID this can be used, this
|
||||||
* is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
|
* is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
|
||||||
|
@ -64,6 +68,11 @@ export function getQueryIndex(viewName: ViewName) {
|
||||||
return `database/${viewName}`
|
return `database/${viewName}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const isExternalTableId = (id: string): boolean => {
|
||||||
|
const matches = id.match(EXTERNAL_TABLE_ID_REGEX)
|
||||||
|
return !!id && matches !== null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a given ID is that of a table.
|
* Check if a given ID is that of a table.
|
||||||
*/
|
*/
|
||||||
|
@ -72,7 +81,7 @@ export const isTableId = (id: string): boolean => {
|
||||||
return (
|
return (
|
||||||
!!id &&
|
!!id &&
|
||||||
(id.startsWith(`${DocumentType.TABLE}${SEPARATOR}`) ||
|
(id.startsWith(`${DocumentType.TABLE}${SEPARATOR}`) ||
|
||||||
id.startsWith(`${DocumentType.DATASOURCE_PLUS}${SEPARATOR}`))
|
isExternalTableId(id))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,8 @@
|
||||||
const screenCount = affectedScreens.length
|
const screenCount = affectedScreens.length
|
||||||
let message = `Removing ${source?.name} `
|
let message = `Removing ${source?.name} `
|
||||||
let initialLength = message.length
|
let initialLength = message.length
|
||||||
|
const hasChanged = () => message.length !== initialLength
|
||||||
|
|
||||||
if (sourceType === SourceType.TABLE) {
|
if (sourceType === SourceType.TABLE) {
|
||||||
const views = "views" in source ? Object.values(source?.views ?? []) : []
|
const views = "views" in source ? Object.values(source?.views ?? []) : []
|
||||||
message += `will delete its data${
|
message += `will delete its data${
|
||||||
|
@ -169,10 +171,10 @@
|
||||||
initialLength !== message.length
|
initialLength !== message.length
|
||||||
? ", and break connected screens:"
|
? ", and break connected screens:"
|
||||||
: "will break connected screens:"
|
: "will break connected screens:"
|
||||||
} else {
|
} else if (hasChanged()) {
|
||||||
message += "."
|
message += "."
|
||||||
}
|
}
|
||||||
return message.length !== initialLength ? message : ""
|
return hasChanged() ? message : ""
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8cbaa80a9cc1152c6cd53722e64da7d824da6e16
|
Subproject commit eb96d8b2f2029033b0f758078ed30c888e8fb249
|
|
@ -8,6 +8,7 @@ import {
|
||||||
SourceType,
|
SourceType,
|
||||||
UsageInScreensResponse,
|
UsageInScreensResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
import { basicDatasourcePlus } from "../../../tests/utilities/structures"
|
||||||
|
|
||||||
const {
|
const {
|
||||||
basicScreen,
|
basicScreen,
|
||||||
|
@ -17,7 +18,6 @@ const {
|
||||||
basicTable,
|
basicTable,
|
||||||
viewV2,
|
viewV2,
|
||||||
basicQuery,
|
basicQuery,
|
||||||
basicDatasource,
|
|
||||||
} = setup.structures
|
} = setup.structures
|
||||||
|
|
||||||
describe("/screens", () => {
|
describe("/screens", () => {
|
||||||
|
@ -225,7 +225,7 @@ describe("/screens", () => {
|
||||||
|
|
||||||
it("should find datasource/query usage", async () => {
|
it("should find datasource/query usage", async () => {
|
||||||
const datasource = await config.api.datasource.create(
|
const datasource = await config.api.datasource.create(
|
||||||
basicDatasource().datasource
|
basicDatasourcePlus().datasource
|
||||||
)
|
)
|
||||||
const query = await config.api.query.save(basicQuery(datasource._id!))
|
const query = await config.api.query.save(basicQuery(datasource._id!))
|
||||||
const screen = await config.api.screen.save(
|
const screen = await config.api.screen.save(
|
||||||
|
|
|
@ -492,6 +492,15 @@ export function basicDatasource(): { datasource: Datasource } {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function basicDatasourcePlus(): { datasource: Datasource } {
|
||||||
|
return {
|
||||||
|
datasource: {
|
||||||
|
...basicDatasource().datasource,
|
||||||
|
plus: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function basicQuery(datasourceId: string): Query {
|
export function basicQuery(datasourceId: string): Query {
|
||||||
return {
|
return {
|
||||||
datasourceId,
|
datasourceId,
|
||||||
|
|
Loading…
Reference in New Issue