Skip to content

fix(docs): strip foreign-schema bleed from per-stack schema docs#305

Open
WhatIfWeDigDeeper wants to merge 2 commits into
mainfrom
fix/schema-doc-cross-schema-bleed
Open

fix(docs): strip foreign-schema bleed from per-stack schema docs#305
WhatIfWeDigDeeper wants to merge 2 commits into
mainfrom
fix/schema-doc-cross-schema-bleed

Conversation

@WhatIfWeDigDeeper
Copy link
Copy Markdown
Owner

Summary

Closes #303.

tbls's --include "\${schema}.*" filter has two limitations the script didn't compensate for:

  • Filters tables, not enums — every per-schema README's ## Enums section listed the union of all 26+ Postgres enum types across every stack's schema. docs/schema/ruby-rails/README.md carried 24 foreign rows even though rails-api defines zero Postgres enums of its own.
  • Treats the . in \${schema}.* as a regex match-any-char — schemas whose names share a prefix (react_nestjs vs react_nestjs_history) bleed each other's tables, schema.json entries, Mermaid entities, and per-table .md files.

This PR:

  1. Adds a post-process pass to scripts/generate-schema-docs.sh that walks each per-schema dir and:
    • drops foreign-schema rows from ## Enums and ## Tables
    • drops Mermaid entity blocks and relation lines for foreign schemas
    • filters schema.json tables[] to own-schema entries only
    • removes leaked ${other_schema}.*.md files
    • drops the ## Enums heading entirely when no own-schema rows remain (rails has none)
  2. Clears each schema dir before invoking tbls — otherwise stale .md files (tables dropped from the DB, like the old express_prisma._prisma_migrations) survive forever and the Mermaid column-swap toggles their content on every run, breaking idempotence.
  3. Regenerates all 11 per-stack schema docs (the visible cleanup).
  4. Adds pkey, fkey, nextval, regclass to cspell — these appear in constraint and sequence-default expressions tbls emits.

Acceptance criteria (per #303)

  • Each docs/schema/<stack>/README.md ## Enums section lists only enums from that stack's schema.
  • docs/schema/ruby-rails/README.md no longer has an ## Enums section.
  • All 11 schema READMEs regenerated and committed in the same PR.
  • scripts/generate-schema-docs.sh continues to be safe to re-run (idempotent).
  • Each docs/schema/<stack>/README.md ## Tables section lists only tables from that stack's schema.
  • Each docs/schema/<stack>/ directory contains only ${schema}.*.md files.
  • Each docs/schema/<stack>/schema.json contains only its own schema's tables.
  • Each docs/schema/<stack>/README.md Mermaid ## Relations diagram contains only its own schema's entities.

Test plan

  • docker compose up -d postgres && npm run docs:schema re-runs cleanly.
  • Re-running produces no diff (idempotent).
  • docs/schema/ruby-rails/README.md has no ## Enums section.
  • docs/schema/react-nestjs/README.md references no react_nestjs_history.* rows.
  • docs/schema/lambda-api/README.md (hand-written DynamoDB docs, outside SCHEMAS) unchanged from main.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 6, 2026 12:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes tbls per-schema documentation bleed by adding a cleanup pass to the schema-doc generation script and regenerating the committed docs/schema/<stack>/ outputs so each stack’s docs only reflect its own Postgres schema.

Changes:

  • Clear each per-stack schema docs directory before running tbls doc to avoid stale .md files and non-idempotent Mermaid column swaps.
  • Post-process generated READMEs to remove foreign-schema rows in ## Tables / ## Enums and foreign entities/relations in Mermaid ERDs; delete leaked ${other_schema}.*.md files; filter schema.json tables to own-schema entries.
  • Update cspell dictionary to accept common constraint/sequence tokens emitted by tbls.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/generate-schema-docs.sh Clears per-stack docs dirs, scopes Mermaid column swap to generated dirs, and adds post-processing to strip foreign-schema leaks.
cspell.config.yaml Adds schema/constraint-related terms to cspell allowlist.
docs/schema/vue-nuxt/README.md Regenerated: removes foreign-schema enum rows from ## Enums.
docs/schema/svelte-hono/README.md Regenerated: removes foreign-schema enum rows from ## Enums.
docs/schema/ruby-rails/schema.json Regenerated: includes rails schema tables; (still includes cross-db enums in .enums).
docs/schema/ruby-rails/ruby_rails.schema_migrations.md New generated table doc.
docs/schema/ruby-rails/ruby_rails.internal_metadata.md New generated table doc.
docs/schema/ruby-rails/README.md Regenerated: removes foreign-schema ## Enums section and includes rails-only tables/relations.
docs/schema/react-nestjs/schema.json Regenerated: removes leaked react_nestjs_history.* table entries.
docs/schema/react-nestjs/README.md Regenerated: removes leaked react_nestjs_history.* tables, enums, and Mermaid entities.
docs/schema/react-nestjs/react_nestjs_history.knex_migrations.md Deleted leaked per-table doc from wrong schema directory.
docs/schema/react-nestjs/react_nestjs_history.knex_migrations_lock.md Deleted leaked per-table doc from wrong schema directory.
docs/schema/react-nestjs/react_nestjs_history.application_history.md Deleted leaked per-table doc from wrong schema directory.
docs/schema/react-nestjs-history/README.md Regenerated: removes foreign-schema enum rows from ## Enums.
docs/schema/react-koa/schema.json Regenerated output (includes normalized constraint expressions).
docs/schema/react-koa/README.md Regenerated: removes foreign-schema enum rows from ## Enums.
docs/schema/python-fastapi/README.md Regenerated: removes foreign-schema enum rows from ## Enums.
docs/schema/java-spring/schema.json Regenerated output (includes normalized constraint expressions).
docs/schema/java-spring/README.md Regenerated: removes foreign-schema enum rows from ## Enums.
docs/schema/graphql-yoga/README.md Regenerated: removes foreign-schema enum rows from ## Enums.
docs/schema/go-gin/schema.json Regenerated output (includes normalized constraint expressions).
docs/schema/go-gin/README.md Regenerated: removes foreign-schema ## Enums section content.
docs/schema/express-prisma/README.md Regenerated: removes foreign-schema enum rows from ## Enums.
docs/schema/express-prisma/express_prisma._prisma_migrations.md Removed stale generated doc for a dropped table.

Comment thread scripts/generate-schema-docs.sh Outdated
Comment thread scripts/generate-schema-docs.sh Outdated
WhatIfWeDigDeeper added a commit that referenced this pull request May 6, 2026
- Make jq a hard requirement (fail fast with install hint) — previously the
  schema.json post-process silently no-op'd when jq was absent, leaving
  foreign-schema tables in the JSON artifacts.
- Filter `.enums` array in schema.json to own-schema entries only; drop the
  `enums` key entirely when no own-schema enums remain (rails, go, and
  react-nestjs-history have none). The `## Enums` README cleanup already
  did this for the markdown side; schema.json now matches.

Co-authored-by: copilot-pull-request-reviewer[bot] <copilot-pull-request-reviewer[bot]@users.noreply.github.com>
@WhatIfWeDigDeeper WhatIfWeDigDeeper requested a review from Copilot May 6, 2026 19:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated no new comments.

WhatIfWeDigDeeper added a commit that referenced this pull request May 6, 2026
…307)

## Summary

Resolves the high-severity Remote Code Execution advisory
[GHSA-hffm-xvc3-vprc](GHSA-hffm-xvc3-vprc)
by bumping the transitive `simple-git` from 3.35.2 → 3.36.0 (via `npm
audit fix`). Pulled in via `nuxt → @nuxt/devtools → simple-git`. Other
packages in the monorepo do not depend on `simple-git`, so no other
lockfiles change.

> Note on wording: "patch" in the PR title is used as a verb ("apply a
fix") — it does **not** imply a semver patch-level bump. 3.35.2 → 3.36.0
is a minor bump, which is what `npm audit fix` recommends as the
smallest available fix for this advisory.

CI's `audit:ci:all` step has been failing on this advisory on every PR
opened against `main`, blocking merges.

This commit was cherry-picked from `feat/understand-codebase-graphs`
(commit `f063bf3`) so the fix can land independently of that feature
branch's review cycle.

## Test plan

- [x] `cd nuxt-api && npx -y audit-ci --config .auditconfig.json` passes
locally.
- [ ] CI `audit:ci:all` passes on this PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

## Update — additional pre-existing CI breakages folded in (seroval
lockfile sync)

After pushing the simple-git fix, CI surfaced additional pre-existing
main-level breakages that had been masked by the audit failure: `npm ci`
was failing in **both** `tanstack-start-ui/` and `react-apollo-ui/`
with:

```
npm error Invalid: lock file's seroval@1.5.2 does not satisfy seroval@1.5.4
npm error Invalid: lock file's seroval-plugins@1.5.2 does not satisfy seroval-plugins@1.5.4
```

`npm install` in each of those directories regenerates their lockfiles
to 1.5.4 for both packages. Folded into this PR because (a) they're the
same shape of pre-existing main breakage and (b) all three must land
before any open PR can pass CI. PRs #305 and #306 are blocked on this PR
landing.

Commits in this PR:

- `9331aa9` fix(deps): bump simple-git in nuxt-api to patch
GHSA-hffm-xvc3-vprc
- `1ade966` fix(deps): sync tanstack-start-ui lockfile (seroval 1.5.2 →
1.5.4)
- `ec44aef` fix(deps): sync react-apollo-ui lockfile (seroval 1.5.2 →
1.5.4)

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
WhatIfWeDigDeeper and others added 2 commits May 6, 2026 17:56
Closes #303.

`tbls`'s `--include "${schema}.*"` filter has two limitations the script
didn't compensate for:

- It filters tables, not enums — so every per-schema README's `## Enums`
  section listed the union of all 26+ Postgres enum types across every
  stack's schema. `docs/schema/ruby-rails/README.md` carried 24 foreign
  rows even though rails-api defines zero Postgres enums of its own.
- It treats the `.` in `${schema}.*` as a regex match-any-char, so
  schemas whose names share a prefix (`react_nestjs` vs
  `react_nestjs_history`) bleed each other's tables, schema.json
  entries, Mermaid entities, and per-table `.md` files.

Add a post-process pass to `scripts/generate-schema-docs.sh` that walks
each per-schema dir and drops foreign-schema rows from `## Enums` and
`## Tables`, drops Mermaid entity blocks and relation lines for foreign
schemas, filters `schema.json` `tables[]` to own-schema entries only,
and removes leaked `${other_schema}.*.md` files. The `## Enums` heading
is dropped entirely when no own-schema rows remain (rails has none).

Also clear each schema dir before invoking `tbls` — otherwise stale
`.md` files (tables that have since been dropped from the DB, like the
old `express_prisma._prisma_migrations`) survive forever and the
Mermaid column-swap toggles their content on every run, breaking
idempotence.

Add `pkey`, `fkey`, `nextval`, `regclass` to cspell — they appear in
constraint and sequence-default expressions tbls emits.

Verified:
- All 11 per-stack `## Enums` sections list only own-schema enums (or
  no section at all when the stack has none).
- `docs/schema/react-nestjs/` contains no `react_nestjs_history.*.md`
  files; its README and schema.json reference only `react_nestjs.*`.
- Re-running `npm run docs:schema` produces no diff (idempotent).
- `docs/schema/lambda-api/` (hand-written DynamoDB docs, not in
  SCHEMAS) is unchanged from `main`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Make jq a hard requirement (fail fast with install hint) — previously the
  schema.json post-process silently no-op'd when jq was absent, leaving
  foreign-schema tables in the JSON artifacts.
- Filter `.enums` array in schema.json to own-schema entries only; drop the
  `enums` key entirely when no own-schema enums remain (rails, go, and
  react-nestjs-history have none). The `## Enums` README cleanup already
  did this for the markdown side; schema.json now matches.

Co-authored-by: copilot-pull-request-reviewer[bot] <copilot-pull-request-reviewer[bot]@users.noreply.github.com>
@WhatIfWeDigDeeper WhatIfWeDigDeeper force-pushed the fix/schema-doc-cross-schema-bleed branch from 01220ab to b746c68 Compare May 6, 2026 21:56
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.

Schema READMEs include foreign-schema enums; ruby-rails has no enums but lists 26

2 participants