Skip to content

Commit

Permalink
fix: make OracleQueryRunner createDatabase if-not-exists not fail
Browse files Browse the repository at this point in the history
  • Loading branch information
imnotjames committed Jul 16, 2021
1 parent 128b982 commit f5a80ef
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/driver/oracle/OracleQueryRunner.ts
Expand Up @@ -310,7 +310,24 @@ export class OracleQueryRunner extends BaseQueryRunner implements QueryRunner {
* Creates a new database.
*/
async createDatabase(database: string, ifNotExist?: boolean): Promise<void> {
await this.query(`CREATE DATABASE IF NOT EXISTS "${database}"`);
// Even with `IF NOT EXISTS` we get:
// ORA-01501: CREATE DATABASE failed
// ORA-01100: database already mounted
if (ifNotExist) {
try {
await this.query(`CREATE DATABASE IF NOT EXISTS "${database}";`);
} catch (e) {
if (e instanceof QueryFailedError) {
if (e.message.includes("ORA-01100: database already mounted")) {
return;
}
}

throw e;
}
} else {
await this.query(`CREATE DATABASE "${database}"`);
}
}

/**
Expand Down

0 comments on commit f5a80ef

Please sign in to comment.