Skip to content

Commit

Permalink
fix: support fully qualified schema in createSchema (#7934)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnotjames committed Jul 20, 2021
1 parent f6af01a commit 94edd12
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/driver/aurora-data-api/AuroraDataApiQueryRunner.ts
Expand Up @@ -283,7 +283,7 @@ export class AuroraDataApiQueryRunner extends BaseQueryRunner implements QueryRu
/**
* Creates a new table schema.
*/
async createSchema(schema: string, ifNotExist?: boolean): Promise<void> {
async createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void> {
throw new TypeORMError(`Schema create queries are not supported by MySql driver.`);
}

Expand Down
7 changes: 5 additions & 2 deletions src/driver/cockroachdb/CockroachQueryRunner.ts
Expand Up @@ -380,7 +380,9 @@ export class CockroachQueryRunner extends BaseQueryRunner implements QueryRunner
/**
* Creates a new table schema.
*/
async createSchema(schema: string, ifNotExist?: boolean): Promise<void> {
async createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void> {
const schema = schemaPath.indexOf(".") === -1 ? schemaPath : schemaPath.split(".")[1];

const up = ifNotExist ? `CREATE SCHEMA IF NOT EXISTS "${schema}"` : `CREATE SCHEMA "${schema}"`;
const down = `DROP SCHEMA "${schema}" CASCADE`;
await this.executeQueries(new Query(up), new Query(down));
Expand All @@ -390,7 +392,8 @@ export class CockroachQueryRunner extends BaseQueryRunner implements QueryRunner
* Drops table schema.
*/
async dropSchema(schemaPath: string, ifExist?: boolean, isCascade?: boolean): Promise<void> {
const schema = schemaPath.indexOf(".") === -1 ? schemaPath : schemaPath.split(".")[0];
const schema = schemaPath.indexOf(".") === -1 ? schemaPath : schemaPath.split(".")[1];

const up = ifExist ? `DROP SCHEMA IF EXISTS "${schema}" ${isCascade ? "CASCADE" : ""}` : `DROP SCHEMA "${schema}" ${isCascade ? "CASCADE" : ""}`;
const down = `CREATE SCHEMA "${schema}"`;
await this.executeQueries(new Query(up), new Query(down));
Expand Down
2 changes: 1 addition & 1 deletion src/driver/mongodb/MongoQueryRunner.ts
Expand Up @@ -566,7 +566,7 @@ export class MongoQueryRunner implements QueryRunner {
/**
* Creates a new table schema.
*/
async createSchema(schema: string, ifNotExist?: boolean): Promise<void> {
async createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void> {
throw new TypeORMError(`Schema create queries are not supported by MongoDB driver.`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/driver/mysql/MysqlQueryRunner.ts
Expand Up @@ -332,7 +332,7 @@ export class MysqlQueryRunner extends BaseQueryRunner implements QueryRunner {
/**
* Creates a new table schema.
*/
async createSchema(schema: string, ifNotExist?: boolean): Promise<void> {
async createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void> {
throw new TypeORMError(`Schema create queries are not supported by MySql driver.`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/driver/oracle/OracleQueryRunner.ts
Expand Up @@ -340,7 +340,7 @@ export class OracleQueryRunner extends BaseQueryRunner implements QueryRunner {
/**
* Creates a new table schema.
*/
async createSchema(schemas: string, ifNotExist?: boolean): Promise<void> {
async createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void> {
throw new TypeORMError(`Schema create queries are not supported by Oracle driver.`);
}

Expand Down
7 changes: 5 additions & 2 deletions src/driver/postgres/PostgresQueryRunner.ts
Expand Up @@ -378,7 +378,9 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
/**
* Creates a new table schema.
*/
async createSchema(schema: string, ifNotExist?: boolean): Promise<void> {
async createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void> {
const schema = schemaPath.indexOf(".") === -1 ? schemaPath : schemaPath.split(".")[1];

const up = ifNotExist ? `CREATE SCHEMA IF NOT EXISTS "${schema}"` : `CREATE SCHEMA "${schema}"`;
const down = `DROP SCHEMA "${schema}" CASCADE`;
await this.executeQueries(new Query(up), new Query(down));
Expand All @@ -388,7 +390,8 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
* Drops table schema.
*/
async dropSchema(schemaPath: string, ifExist?: boolean, isCascade?: boolean): Promise<void> {
const schema = schemaPath.indexOf(".") === -1 ? schemaPath : schemaPath.split(".")[0];
const schema = schemaPath.indexOf(".") === -1 ? schemaPath : schemaPath.split(".")[1];

const up = ifExist ? `DROP SCHEMA IF EXISTS "${schema}" ${isCascade ? "CASCADE" : ""}` : `DROP SCHEMA "${schema}" ${isCascade ? "CASCADE" : ""}`;
const down = `CREATE SCHEMA "${schema}"`;
await this.executeQueries(new Query(up), new Query(down));
Expand Down
4 changes: 3 additions & 1 deletion src/driver/sap/SapQueryRunner.ts
Expand Up @@ -342,7 +342,9 @@ export class SapQueryRunner extends BaseQueryRunner implements QueryRunner {
/**
* Creates a new table schema.
*/
async createSchema(schema: string, ifNotExist?: boolean): Promise<void> {
async createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void> {
const schema = schemaPath.indexOf(".") === -1 ? schemaPath : schemaPath.split(".")[1];

let exist = false;
if (ifNotExist) {
const result = await this.query(`SELECT * FROM "SYS"."SCHEMAS" WHERE "SCHEMA_NAME" = '${schema}'`);
Expand Down
2 changes: 1 addition & 1 deletion src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts
Expand Up @@ -225,7 +225,7 @@ export abstract class AbstractSqliteQueryRunner extends BaseQueryRunner implemen
/**
* Creates a new table schema.
*/
async createSchema(schema: string, ifNotExist?: boolean): Promise<void> {
async createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void> {
return Promise.resolve();
}

Expand Down

0 comments on commit 94edd12

Please sign in to comment.