From 9643a54035e2c26384d4681cffc3216c69500994 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Wed, 15 May 2024 23:59:15 -0500 Subject: [PATCH 1/3] fix(main): escape underscore to avoid over-ignoring schemas fix #92 --- src/main.ts | 4 ++-- src/pg-structure/constraint/foreign-key.ts | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 75ff528..ff4fe76 100644 --- a/src/main.ts +++ b/src/main.ts @@ -82,8 +82,8 @@ async function getSchemas( const where: string[] = ["NOT pg_is_other_temp_schema(oid)", "nspname <> 'pg_toast'"]; const whereInclude: string[] = []; const parameters: string[] = []; - const includedPatterns = include.concat(system && include.length > 0 ? ["information_schema", "pg_%"] : []); - const excludedPatterns = exclude.concat(system ? [] : ["information_schema", "pg_%"]); + const includedPatterns = include.concat(system && include.length > 0 ? ["information\\_schema", "pg\\_%"] : []); + const excludedPatterns = exclude.concat(system ? [] : ["information\\_schema", "pg\\_%"]); includedPatterns.forEach((pattern, i) => { whereInclude.push(`nspname LIKE $${i + 1}`); // nspname LIKE $1 diff --git a/src/pg-structure/constraint/foreign-key.ts b/src/pg-structure/constraint/foreign-key.ts index 869d6dd..a7f8d62 100644 --- a/src/pg-structure/constraint/foreign-key.ts +++ b/src/pg-structure/constraint/foreign-key.ts @@ -31,6 +31,9 @@ export default class ForeignKey extends Constraint { this.columns = IndexableArray.throwingFrom(args.columns, "name"); this.table = args.table; this.mandatoryParent = this.columns.every((column) => column.notNull); + if (this.index === undefined) { + throw new Error(`Foreign key ${this.fullName} did not find an index, it might be in another schema`); + } } /** From 2a9985efe17285a8d02d81fe5f5921de6a4351c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96z=C3=BCm=20Eldo=C4=9Fan?= Date: Thu, 16 May 2024 08:26:07 +0300 Subject: [PATCH 2/3] fix: add coverage exception --- src/pg-structure/constraint/foreign-key.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pg-structure/constraint/foreign-key.ts b/src/pg-structure/constraint/foreign-key.ts index a7f8d62..278e472 100644 --- a/src/pg-structure/constraint/foreign-key.ts +++ b/src/pg-structure/constraint/foreign-key.ts @@ -31,9 +31,8 @@ export default class ForeignKey extends Constraint { this.columns = IndexableArray.throwingFrom(args.columns, "name"); this.table = args.table; this.mandatoryParent = this.columns.every((column) => column.notNull); - if (this.index === undefined) { - throw new Error(`Foreign key ${this.fullName} did not find an index, it might be in another schema`); - } + /* istanbul ignore if */ + if (this.index === undefined) throw new Error(`Foreign key ${this.fullName} did not find an index, it might be in another schema`); } /** From 3d3080fc75540d82e95a150fedfb1b24240962d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96z=C3=BCm=20Eldo=C4=9Fan?= Date: Thu, 16 May 2024 08:27:50 +0300 Subject: [PATCH 3/3] doc: add comment about SQL wildcard. --- src/types/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/index.ts b/src/types/index.ts index b15cca6..cbb3449 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -154,7 +154,7 @@ export interface Options { * List of the schemas or a pattern similar to SQL's `LIKE` to select included schemas. * * @example - * const config = { includeSchemas: "public_%" }; // include all schemas starting with "public_" + * const config = { includeSchemas: "public\\_%" }; // include all schemas starting with "public_". `_` is an SQL wildcard character. You should escape it. * * @example * const config = { includeSchemas: ["public", "extra"] };