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 { 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
|
||||
* 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}`
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
|
@ -72,7 +81,7 @@ export const isTableId = (id: string): boolean => {
|
|||
return (
|
||||
!!id &&
|
||||
(id.startsWith(`${DocumentType.TABLE}${SEPARATOR}`) ||
|
||||
id.startsWith(`${DocumentType.DATASOURCE_PLUS}${SEPARATOR}`))
|
||||
isExternalTableId(id))
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -151,6 +151,8 @@
|
|||
const screenCount = affectedScreens.length
|
||||
let message = `Removing ${source?.name} `
|
||||
let initialLength = message.length
|
||||
const hasChanged = () => message.length !== initialLength
|
||||
|
||||
if (sourceType === SourceType.TABLE) {
|
||||
const views = "views" in source ? Object.values(source?.views ?? []) : []
|
||||
message += `will delete its data${
|
||||
|
@ -169,10 +171,10 @@
|
|||
initialLength !== message.length
|
||||
? ", and break connected screens:"
|
||||
: "will break connected screens:"
|
||||
} else {
|
||||
} else if (hasChanged()) {
|
||||
message += "."
|
||||
}
|
||||
return message.length !== initialLength ? message : ""
|
||||
return hasChanged() ? message : ""
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 8cbaa80a9cc1152c6cd53722e64da7d824da6e16
|
||||
Subproject commit eb96d8b2f2029033b0f758078ed30c888e8fb249
|
|
@ -8,6 +8,7 @@ import {
|
|||
SourceType,
|
||||
UsageInScreensResponse,
|
||||
} from "@budibase/types"
|
||||
import { basicDatasourcePlus } from "../../../tests/utilities/structures"
|
||||
|
||||
const {
|
||||
basicScreen,
|
||||
|
@ -17,7 +18,6 @@ const {
|
|||
basicTable,
|
||||
viewV2,
|
||||
basicQuery,
|
||||
basicDatasource,
|
||||
} = setup.structures
|
||||
|
||||
describe("/screens", () => {
|
||||
|
@ -225,7 +225,7 @@ describe("/screens", () => {
|
|||
|
||||
it("should find datasource/query usage", async () => {
|
||||
const datasource = await config.api.datasource.create(
|
||||
basicDatasource().datasource
|
||||
basicDatasourcePlus().datasource
|
||||
)
|
||||
const query = await config.api.query.save(basicQuery(datasource._id!))
|
||||
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 {
|
||||
return {
|
||||
datasourceId,
|
||||
|
|
Loading…
Reference in New Issue