Skip to content

Commit fb77e75

Browse files
committed
fix(redshift-driver): Use Redshift schema query.
Fixes #3876.
1 parent 62dfe3a commit fb77e75

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/cubejs-redshift-driver/src/RedshiftDriver.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ export class RedshiftDriver extends PostgresDriver<RedshiftDriverConfiguration>
2222
super(options);
2323
}
2424

25+
/**
26+
* @param {string} schemaName
27+
* @return {Promise<Array<unknown>>}
28+
*/
29+
async createSchemaIfNotExists(schemaName: string) {
30+
const schemaExistsQuery = `SELECT nspname FROM pg_namespace where nspname = ${this.param(0)}`;
31+
const schemas = await this.query(schemaExistsQuery, [schemaName])
32+
if (schemas.length === 0) {
33+
return this.query(`CREATE SCHEMA IF NOT EXISTS ${schemaName}`);
34+
}
35+
return null;
36+
}
37+
2538
protected getInitialConfiguration(): Partial<RedshiftDriverConfiguration> {
2639
return {
2740
// @todo It's not possible to support UNLOAD in readOnly mode, because we need column types (CREATE TABLE?)

0 commit comments

Comments
 (0)