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]) { const schemaName = this.connectionConfig.searchPath?.[0] || 'public';
await this.sqlClient.raw(
` CREATE SCHEMA IF NOT EXISTS ?? AUTHORIZATION ?? `, // Check schemaExists because `CREATE SCHEMA IF NOT EXISTS` requires permissions of `CREATE ON DATABASE`
[ const schemaExists = !!(
(this.connectionConfig.searchPath && await this.sqlClient.raw(
this.connectionConfig.searchPath[0]) || `SELECT schema_name FROM information_schema.schemata WHERE schema_name = ?`,
'public', [schemaName]
this.connectionConfig.connection.user, )
] ).rows?.[0];
);
// } if(!schemaExists) {
await this.sqlClient.raw(
`CREATE SCHEMA IF NOT EXISTS ?? AUTHORIZATION ?? `,
[schemaName, this.connectionConfig.connection.user]
);
}
// this.sqlClient = knex(this.connectionConfig); // this.sqlClient = knex(this.connectionConfig);
} catch (e) { } catch (e) {

Loading…
Cancel
Save