Browse Source

Merge pull request #5399 from data-envoy/fix/pg-data-source-wo-create-on-db-permission

fix(nocodb): Add postgres data source w/o `CREATE ON DATABASE` permission
pull/5413/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
b222ab7542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      packages/nocodb/src/lib/db/sql-client/lib/pg/PgClient.ts

27
packages/nocodb/src/lib/db/sql-client/lib/pg/PgClient.ts

@ -474,17 +474,22 @@ class PGClient extends KnexClient {
]);
}
// if (this.connectionConfig.searchPath && this.connectionConfig.searchPath[0]) {
await this.sqlClient.raw(
` CREATE SCHEMA IF NOT EXISTS ?? AUTHORIZATION ?? `,
[
(this.connectionConfig.searchPath &&
this.connectionConfig.searchPath[0]) ||
'public',
this.connectionConfig.connection.user,
]
);
// }
const schemaName = this.connectionConfig.searchPath?.[0] || 'public';
// Check schemaExists because `CREATE SCHEMA IF NOT EXISTS` requires permissions of `CREATE ON DATABASE`
const schemaExists = !!(
await this.sqlClient.raw(
`SELECT schema_name FROM information_schema.schemata WHERE schema_name = ?`,
[schemaName]
)
).rows?.[0];
if(!schemaExists) {
await this.sqlClient.raw(
`CREATE SCHEMA IF NOT EXISTS ?? AUTHORIZATION ?? `,
[schemaName, this.connectionConfig.connection.user]
);
}
// this.sqlClient = knex(this.connectionConfig);
} catch (e) {

Loading…
Cancel
Save