Skip to content

Commit

Permalink
Merge pull request #93 from stephenh/fix-excluding-pgsodium-schema
Browse files Browse the repository at this point in the history
fix(main): escape underscore to avoid over-ignoring schemas
  • Loading branch information
ozum authored May 16, 2024
2 parents 0c197a0 + 3d3080f commit eee84a9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/pg-structure/constraint/foreign-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +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);
/* 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`);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"] };
Expand Down

0 comments on commit eee84a9

Please sign in to comment.