Skip to content

fix(migrations): reject temp schema objects - #2517

Merged
JSONbored merged 4 commits into
mainfrom
codex/fix-d1-migration-guard-for-temp-schemas
Jul 2, 2026
Merged

fix(migrations): reject temp schema objects#2517
JSONbored merged 4 commits into
mainfrom
codex/fix-d1-migration-guard-for-temp-schemas

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • The D1 compatibility scanner only detected CREATE TEMP/CREATE TEMPORARY forms and missed schema-qualified temporary objects like CREATE TABLE temp.scratch, allowing D1-incompatible migrations to pass CI and fail at remote apply.

Description

  • Extend the D1 forbidden-patterns in scripts/check-migrations.mjs to also match schema-qualified temp objects by adding a regex that catches CREATE ... temp. for table, index, view, and trigger forms.
  • Preserve the existing comment/string literal blanking and anchored checks so keywords in comments/strings or trigger bodies do not false-positive.
  • Add regression cases to test/unit/check-migrations-script.test.ts to cover CREATE TABLE temp.scratch and a temp schema index, and expand the existing TEMP/TEMPORARY coverage into a parameterized test.

Testing

  • Ran the updated unit test file with npx vitest run test/unit/check-migrations-script.test.ts and observed all tests pass (11 passed).
  • Ran the migration guard via npm run db:migrations:check and it reported the repository migrations OK (no new duplicates and next free number reported).
  • Attempted full gate with npm run test:ci, but npm run actionlint could not complete due to network resolution issues to github.com and the actionlint fallback reported unknown self-hosted runner labels in unchanged workflow files, so the full gate could not be completed locally.
  • Attempted npm audit --audit-level=moderate, but the npm audit endpoint returned 403 Forbidden, so that check could not be completed here.

Codex Task

@loopover-orb

loopover-orb Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-02 08:46:27 UTC

2 files · 1 AI reviewer · no blockers · readiness 91/100 · CI pending · blocked

⏸️ Suggested Action - Manual Review

  • Touches a guarded path — held for manual review

Review summary
This change correctly broadens the migration guard from only `CREATE TEMP`/`CREATE TEMPORARY` to also catch temp-schema objects, including quoted `temp` schema qualifiers. The `cleanSql` update preserves quoted schema qualifiers only when followed by a dot, which keeps the new unanchored regex from false-positiveing ordinary quoted values or identifiers. The added tests exercise the important positive paths and several false-positive cases, so the visible diff is safe enough to proceed.

Nits — 5 non-blocking
  • nit: scripts/check-migrations.mjs:45 permits `UNIQUE` before every object type in the regex even though only indexes can be unique; scoping that optional prefix to `index` would make the grammar intent tighter.
  • nit: scripts/check-migrations.mjs:61-78 now carries a long parser-design explanation inline; consider moving most examples to the regression tests and keeping the production comment focused on the invariant.
  • scripts/check-migrations.mjs:45: Split the temp-schema regex into named subpatterns or a small helper constant so future edits do not have to reason through the full expression in one line.
  • test/unit/check-migrations-script.test.ts:38: Add one direct `CREATE TABLE IF NOT EXISTS temp.scratch` case if you want explicit coverage that the shared `IF NOT EXISTS` branch works outside indexes.
  • Touches a guarded path — held for manual review — A maintainer must review and merge this change.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ⚠️ Missing No linked issue or no-issue rationale found.
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (size label size:M; no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 65 registered-repo PR(s), 55 merged, 548 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 65 PR(s), 548 issue(s).
Gate result ⚠️ Not blocking Advisory; not blocking this PR.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: not available
  • Official Gittensor activity: 65 PR(s), 548 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • Explain no-issue PR.
  • No action.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@loopover-orb loopover-orb Bot added gittensor gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. labels Jul 2, 2026
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.95%. Comparing base (67e7b03) to head (36156b6).
⚠️ Report is 30 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2517   +/-   ##
=======================================
  Coverage   95.95%   95.95%           
=======================================
  Files         226      226           
  Lines       25391    25427   +36     
  Branches     9234     9245   +11     
=======================================
+ Hits        24363    24399   +36     
  Misses        417      417           
  Partials      611      611           
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

JSONbored added 2 commits July 2, 2026 00:10
The temp-schema regex anchored table|index|view|trigger directly
after `create`, so `CREATE UNIQUE INDEX temp.idx ...` slipped past
the D1 remote-authorizer guard despite being rejected at deploy.
@JSONbored
JSONbored force-pushed the codex/fix-d1-migration-guard-for-temp-schemas branch from b902058 to 31f9495 Compare July 2, 2026 07:13
…chema

cleanSql blanked the contents of double-quoted, backtick-quoted, and
bracket-quoted identifiers the same way it blanks string literals,
hiding a legitimate "temp".scratch (or `temp`.scratch, [temp].scratch)
reference from the D1_FORBIDDEN temp-schema scan. Also close the same
gap for SQLite's single-quote-as-identifier fallback ('temp'.scratch),
distinguishing it from an ordinary string value by checking whether the
closing quote is immediately followed by a schema-qualifying dot.
@dosubot dosubot Bot added size:M and removed size:XS labels Jul 2, 2026
…qualified

The temp-schema pattern in D1_FORBIDDEN is deliberately unanchored, so
unconditionally preserving every quoted identifier's text let an
ordinary column/table name that merely spells out forbidden-looking
text (e.g. a column named "create temp note") leak into the scan and
false-positive. Unify all four quoting styles (', ", `, []) under one
rule: only preserve content when the closing quote is immediately
followed by a schema-qualifying dot; otherwise blank it like a value.
@JSONbored
JSONbored merged commit 08fb691 into main Jul 2, 2026
12 checks passed
@JSONbored
JSONbored deleted the codex/fix-d1-migration-guard-for-temp-schemas branch July 2, 2026 08:50
@github-project-automation github-project-automation Bot moved this from Todo to Done in gittensory - v1 roadmap Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant