Adding error handling for table names or columns which contain dots (invalid).
This commit is contained in:
parent
35c1f5bbce
commit
4068df6025
|
@ -2,10 +2,6 @@ SELECT 'CREATE DATABASE main'
|
|||
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'main')\gexec
|
||||
CREATE SCHEMA "test-1";
|
||||
CREATE TYPE person_job AS ENUM ('qa', 'programmer', 'designer', 'support');
|
||||
CREATE TABLE "Bad.Table" (
|
||||
BadID SERIAL PRIMARY KEY,
|
||||
"Bad.Column" text
|
||||
);
|
||||
CREATE TABLE Persons (
|
||||
PersonID SERIAL PRIMARY KEY,
|
||||
LastName varchar(255),
|
||||
|
|
|
@ -3,12 +3,33 @@ import {
|
|||
DatasourcePlus,
|
||||
IntegrationBase,
|
||||
Schema,
|
||||
Table,
|
||||
} from "@budibase/types"
|
||||
import * as datasources from "./datasources"
|
||||
import tableSdk from "../tables"
|
||||
import { getIntegration } from "../../../integrations"
|
||||
import { context } from "@budibase/backend-core"
|
||||
|
||||
function checkForSchemaErrors(schema: Record<string, Table>) {
|
||||
const errors: Record<string, string> = {}
|
||||
for (let [tableName, table] of Object.entries(schema)) {
|
||||
if (tableName.includes(".")) {
|
||||
errors[tableName] = "Table names containing dots are not supported."
|
||||
} else {
|
||||
const columnNames = Object.keys(table.schema)
|
||||
const invalidColumnName = columnNames.find(columnName =>
|
||||
columnName.includes(".")
|
||||
)
|
||||
if (invalidColumnName) {
|
||||
errors[
|
||||
tableName
|
||||
] = `Column '${invalidColumnName}' is not supported as it contains a dot.`
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors
|
||||
}
|
||||
|
||||
export async function buildFilteredSchema(
|
||||
datasource: Datasource,
|
||||
filter?: string[]
|
||||
|
@ -30,16 +51,19 @@ export async function buildFilteredSchema(
|
|||
filteredSchema.errors[key] = schema.errors[key]
|
||||
}
|
||||
}
|
||||
return filteredSchema
|
||||
|
||||
return {
|
||||
...filteredSchema,
|
||||
errors: {
|
||||
...filteredSchema.errors,
|
||||
...checkForSchemaErrors(filteredSchema.tables),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async function buildSchemaHelper(datasource: Datasource): Promise<Schema> {
|
||||
const connector = (await getConnector(datasource)) as DatasourcePlus
|
||||
const externalSchema = await connector.buildSchema(
|
||||
datasource._id!,
|
||||
datasource.entities!
|
||||
)
|
||||
return externalSchema
|
||||
return await connector.buildSchema(datasource._id!, datasource.entities!)
|
||||
}
|
||||
|
||||
export async function getConnector(
|
||||
|
|
Loading…
Reference in New Issue