Skip to content

Commit

Permalink
fix: fix table loading when schemas are used
Browse files Browse the repository at this point in the history
  • Loading branch information
imnotjames committed Jul 16, 2021
1 parent f5a80ef commit 3a106a3
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/driver/oracle/OracleQueryRunner.ts
Expand Up @@ -1258,13 +1258,20 @@ export class OracleQueryRunner extends BaseQueryRunner implements QueryRunner {
dbTables.push(...await this.query(tablesSql));
} else {
const tablesCondition = tableNames.map(tableName => {
let [schema, name] = tableName.split(".");
if (!name) {
name = schema;
schema = this.driver.options.schema || currentSchema;
const parts = tableName.split(".");

if (parts.length >= 3) {
const [ , schema, name ] = parts;
return `("OWNER" = '${schema}' AND "TABLE_NAME" = '${name}')`
} else if (parts.length === 2) {
const [ schema, name ] = parts;
return `("OWNER" = '${schema}' AND "TABLE_NAME" = '${name}')`
} else if (parts.length === 1) {
const [ name ] = parts;
return `("TABLE_NAME" = '${name}')`
} else {
return `(1=0)`
}

return `("OWNER" = '${schema}' AND "TABLE_NAME" = '${name}')`
}).join(" OR ");
const tablesSql = `SELECT "TABLE_NAME", "OWNER" FROM "ALL_TABLES" WHERE ${tablesCondition}`;
dbTables.push(...await this.query(tablesSql));
Expand Down Expand Up @@ -1324,17 +1331,17 @@ export class OracleQueryRunner extends BaseQueryRunner implements QueryRunner {
.map(dbColumn => {
const columnConstraints = dbConstraints.filter(
dbConstraint => (
dbConstraint["OWNER"] === dbTable["OWNER"] &&
dbConstraint["TABLE_NAME"] === dbTable["TABLE_NAME"] &&
dbConstraint["OWNER"] === dbColumn["OWNER"] &&
dbConstraint["TABLE_NAME"] === dbColumn["TABLE_NAME"] &&
dbConstraint["COLUMN_NAME"] === dbColumn["COLUMN_NAME"]
)
);

const uniqueConstraint = columnConstraints.find(constraint => constraint["CONSTRAINT_TYPE"] === "U");
const isConstraintComposite = uniqueConstraint
? !!dbConstraints.find(dbConstraint => (
dbConstraint["OWNER"] === dbTable["OWNER"] &&
dbConstraint["TABLE_NAME"] === dbTable["TABLE_NAME"] &&
dbConstraint["OWNER"] === dbColumn["OWNER"] &&
dbConstraint["TABLE_NAME"] === dbColumn["TABLE_NAME"] &&
dbConstraint["COLUMN_NAME"] !== dbColumn["COLUMN_NAME"] &&
dbConstraint["CONSTRAINT_NAME"] === uniqueConstraint["CONSTRAINT_NAME"] &&
dbConstraint["CONSTRAINT_TYPE"] === "U"
Expand Down

0 comments on commit 3a106a3

Please sign in to comment.