Merge pull request #13372 from Budibase/fix/better-datasource-defaults

Better datasource default hosts
This commit is contained in:
Michael Drury 2024-03-28 15:09:42 +00:00 committed by GitHub
commit f9e78652bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 25 additions and 9 deletions

View File

@ -9,6 +9,7 @@ import {
QueryType, QueryType,
} from "@budibase/types" } from "@budibase/types"
import { db as dbCore } from "@budibase/backend-core" import { db as dbCore } from "@budibase/backend-core"
import { HOST_ADDRESS } from "./utils"
interface CouchDBConfig { interface CouchDBConfig {
url: string url: string
@ -28,7 +29,7 @@ const SCHEMA: Integration = {
url: { url: {
type: DatasourceFieldType.STRING, type: DatasourceFieldType.STRING,
required: true, required: true,
default: "http://localhost:5984", default: `http://${HOST_ADDRESS}:5984`,
}, },
database: { database: {
type: DatasourceFieldType.STRING, type: DatasourceFieldType.STRING,

View File

@ -8,6 +8,7 @@ import {
} from "@budibase/types" } from "@budibase/types"
import { Client, ClientOptions } from "@elastic/elasticsearch" import { Client, ClientOptions } from "@elastic/elasticsearch"
import { HOST_ADDRESS } from "./utils"
interface ElasticsearchConfig { interface ElasticsearchConfig {
url: string url: string
@ -29,7 +30,7 @@ const SCHEMA: Integration = {
url: { url: {
type: DatasourceFieldType.STRING, type: DatasourceFieldType.STRING,
required: true, required: true,
default: "http://localhost:9200", default: `http://${HOST_ADDRESS}:9200`,
}, },
ssl: { ssl: {
type: DatasourceFieldType.BOOLEAN, type: DatasourceFieldType.BOOLEAN,

View File

@ -22,6 +22,7 @@ import {
finaliseExternalTables, finaliseExternalTables,
SqlClient, SqlClient,
checkExternalTables, checkExternalTables,
HOST_ADDRESS,
} from "./utils" } from "./utils"
import Sql from "./base/sql" import Sql from "./base/sql"
import { MSSQLTablesResponse, MSSQLColumn } from "./base/types" import { MSSQLTablesResponse, MSSQLColumn } from "./base/types"
@ -88,7 +89,6 @@ const SCHEMA: Integration = {
user: { user: {
type: DatasourceFieldType.STRING, type: DatasourceFieldType.STRING,
required: true, required: true,
default: "localhost",
}, },
password: { password: {
type: DatasourceFieldType.PASSWORD, type: DatasourceFieldType.PASSWORD,
@ -96,7 +96,7 @@ const SCHEMA: Integration = {
}, },
server: { server: {
type: DatasourceFieldType.STRING, type: DatasourceFieldType.STRING,
default: "localhost", default: HOST_ADDRESS,
}, },
port: { port: {
type: DatasourceFieldType.NUMBER, type: DatasourceFieldType.NUMBER,

View File

@ -22,6 +22,7 @@ import {
InsertManyResult, InsertManyResult,
} from "mongodb" } from "mongodb"
import environment from "../environment" import environment from "../environment"
import { HOST_ADDRESS } from "./utils"
export interface MongoDBConfig { export interface MongoDBConfig {
connectionString: string connectionString: string
@ -51,7 +52,7 @@ const getSchema = () => {
connectionString: { connectionString: {
type: DatasourceFieldType.STRING, type: DatasourceFieldType.STRING,
required: true, required: true,
default: "mongodb://localhost:27017", default: `mongodb://${HOST_ADDRESS}:27017`,
display: "Connection string", display: "Connection string",
}, },
db: { db: {

View File

@ -21,6 +21,7 @@ import {
generateColumnDefinition, generateColumnDefinition,
finaliseExternalTables, finaliseExternalTables,
checkExternalTables, checkExternalTables,
HOST_ADDRESS,
} from "./utils" } from "./utils"
import dayjs from "dayjs" import dayjs from "dayjs"
import { NUMBER_REGEX } from "../utilities" import { NUMBER_REGEX } from "../utilities"
@ -49,7 +50,7 @@ const SCHEMA: Integration = {
datasource: { datasource: {
host: { host: {
type: DatasourceFieldType.STRING, type: DatasourceFieldType.STRING,
default: "localhost", default: HOST_ADDRESS,
required: true, required: true,
}, },
port: { port: {

View File

@ -22,6 +22,7 @@ import {
finaliseExternalTables, finaliseExternalTables,
getSqlQuery, getSqlQuery,
SqlClient, SqlClient,
HOST_ADDRESS,
} from "./utils" } from "./utils"
import Sql from "./base/sql" import Sql from "./base/sql"
import { import {
@ -63,7 +64,7 @@ const SCHEMA: Integration = {
datasource: { datasource: {
host: { host: {
type: DatasourceFieldType.STRING, type: DatasourceFieldType.STRING,
default: "localhost", default: HOST_ADDRESS,
required: true, required: true,
}, },
port: { port: {

View File

@ -21,6 +21,7 @@ import {
finaliseExternalTables, finaliseExternalTables,
SqlClient, SqlClient,
checkExternalTables, checkExternalTables,
HOST_ADDRESS,
} from "./utils" } from "./utils"
import Sql from "./base/sql" import Sql from "./base/sql"
import { PostgresColumn } from "./base/types" import { PostgresColumn } from "./base/types"
@ -72,7 +73,7 @@ const SCHEMA: Integration = {
datasource: { datasource: {
host: { host: {
type: DatasourceFieldType.STRING, type: DatasourceFieldType.STRING,
default: "localhost", default: HOST_ADDRESS,
required: true, required: true,
}, },
port: { port: {

View File

@ -6,6 +6,7 @@ import {
QueryType, QueryType,
} from "@budibase/types" } from "@budibase/types"
import Redis from "ioredis" import Redis from "ioredis"
import { HOST_ADDRESS } from "./utils"
interface RedisConfig { interface RedisConfig {
host: string host: string
@ -28,7 +29,7 @@ const SCHEMA: Integration = {
host: { host: {
type: DatasourceFieldType.STRING, type: DatasourceFieldType.STRING,
required: true, required: true,
default: "localhost", default: HOST_ADDRESS,
}, },
port: { port: {
type: DatasourceFieldType.NUMBER, type: DatasourceFieldType.NUMBER,

View File

@ -13,6 +13,7 @@ import {
DEFAULT_BB_DATASOURCE_ID, DEFAULT_BB_DATASOURCE_ID,
} from "../constants" } from "../constants"
import { helpers } from "@budibase/shared-core" import { helpers } from "@budibase/shared-core"
import env from "../environment"
const DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}` const DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}`
const ROW_ID_REGEX = /^\[.*]$/g const ROW_ID_REGEX = /^\[.*]$/g
@ -92,6 +93,14 @@ export enum SqlClient {
ORACLE = "oracledb", ORACLE = "oracledb",
} }
const isCloud = env.isProd() && !env.SELF_HOSTED
const isSelfHost = env.isProd() && env.SELF_HOSTED
export const HOST_ADDRESS = isSelfHost
? "host.docker.internal"
: isCloud
? ""
: "localhost"
export function isExternalTableID(tableId: string) { export function isExternalTableID(tableId: string) {
return tableId.includes(DocumentType.DATASOURCE) return tableId.includes(DocumentType.DATASOURCE)
} }