Skip to content

Schema filtering - #30

Merged
aersam merged 5 commits into
mainfrom
schema-filtering
Sep 8, 2026
Merged

Schema filtering#30
aersam merged 5 commits into
mainfrom
schema-filtering

Conversation

@aersam

@aersam aersam commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

No description provided.

aersam and others added 5 commits September 7, 2026 20:31
Composable with the existing -- area: tag filtering, but derived
automatically by parsing each file's SQL instead of requiring a tag.
Wired into pgdb compare, migrate check/apply, and testdb up/reset
(the latter two also gain --area/--exclude-area, which they lacked
entirely until now).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01StWgZw5TDd7KNGY3VzNGMg
…refs

The EXEC(...)-literal-misparse guard in sql_schemas() rejected any Table
node without an identifier-shaped name, including the legitimate empty
name sqlglot gives a bare CREATE SCHEMA (whose name lives in `db`, not
`this`). That silently dropped the CREATE SCHEMA's schema whenever the
same file had another real table reference too (the empty-schemas
regex-fallback safety net never triggered). Found by code review.

Also de-duplicates the system-schema exclusion list (pg_catalog/
information_schema/sys) into dialect.SYSTEM_SCHEMAS, shared by
schemas.py and testdb/schema.py instead of each keeping its own copy.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01StWgZw5TDd7KNGY3VzNGMg
New public surface (pgdevkit.schemas module, --schema/--exclude-schema
on compare/migrate check/apply, --area/--exclude-area and
--schema/--exclude-schema on testdb up/reset) warrants a minor bump,
not a patch. auto-release.yml tags/releases/publishes automatically
once this lands on main.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AggszcqpDQAqPPEJCVVCLM
Verified empirically that parse_directory() and _iter_sql_files()
already skip parse_areas()/sql_schemas() entirely when that axis
isn't being filtered on (each is gated by "(areas or exclude_areas)
and ..." / "(schemas or exclude_schemas) and ..."), and that
filter_by_area()/filter_by_schema() never touch the filesystem when
neither only nor exclude is set -- no behavior change needed, this
was already the case. Adds explicit call-counting tests so a future
edit can't silently make either check unconditional.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AggszcqpDQAqPPEJCVVCLM
- sql_schemas()'s regex fallback scanned raw file text, so a schema
  merely *mentioned* in a "--" comment (e.g. "-- see billing.invoice
  for context") was wrongly detected as a real reference, defeating
  both --schema (falsely excluded) and --exclude-schema (falsely
  dropped) for such a file. Fixed by stripping comments first, via a
  comment-stripper extracted out of migrate.py into a new shared
  pgdevkit/sql_text.py module (schemas.py couldn't import migrate.py's
  copy directly -- migrate.py already imports schemas.py).

- The guard against sqlglot's EXEC(...)-literal misparse required a
  table's name to fully match \w+, which also rejected legitimate
  quoted identifiers containing punctuation (e.g. billing."my-table"),
  silently dropping that table's schema. Loosened to reject only names
  containing whitespace, which still catches the original misparse (a
  full SQL statement embedded as literal text) without rejecting real
  quoted identifiers.

Both reproduced and confirmed fixed against sql_schemas() directly;
regression tests added for each, plus for the existing EXEC(...) and
bare-CREATE-SCHEMA cases they abut.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AggszcqpDQAqPPEJCVVCLM
@aersam
aersam merged commit 78641d8 into main Sep 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant