Skip to content

fix(db): tolerate SQLite's optional COLUMN keyword in ALTER TABLE parsing (#8368)#8457

Closed
philluiz2323 wants to merge 1 commit into
JSONbored:mainfrom
philluiz2323:fix-migration-column-extraction-optional-keyword-8368
Closed

fix(db): tolerate SQLite's optional COLUMN keyword in ALTER TABLE parsing (#8368)#8457
philluiz2323 wants to merge 1 commit into
JSONbored:mainfrom
philluiz2323:fix-migration-column-extraction-optional-keyword-8368

Conversation

@philluiz2323

Copy link
Copy Markdown
Contributor

Summary

  • extractSchemaEvents' three regexes (renameColumnMatch, dropColumnMatch, addColumnMatch) all required the literal COLUMN keyword, but SQLite's actual ALTER TABLE grammar makes it optional for all three forms — ALTER TABLE t ADD x INTEGER, ALTER TABLE t DROP x, and ALTER TABLE t RENAME x TO y are all valid statements that omit it (verified directly against real sqlite3).
  • A migration written with the terser (equally valid) syntax produced zero SchemaEvents for that statement — completely invisible to detectColumnCollisions, silently defeating the CI gate this parser powers (db:migrations:check).
  • Changes \s+COLUMN\s+ to \s+(?:COLUMN\s+)? in all three regexes so both forms are correctly detected. No other parsing or collision-detection logic changed.
  • Adds test cases for the COLUMN-absent form of all three statement types, alongside the existing COLUMN-present tests (all of which continue to pass unmodified).

Closes #8368

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked an issue, or this is small enough that the summary explains why an issue is not needed.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally; codecov/patch requires ≥99% coverage of the lines AND branches you changed (aim for 100% on your diff so CI variance does not fail near the threshold). Global coverage is a non-blocking trend with a loose 90% backstop, not the gate.
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • This change touches only src/db/migration-column-extraction.ts (pure regex/parsing logic, no UI/MCP/workers/OpenAPI surface) plus its test file. Verified via npx vitest run test/unit/migration-column-extraction.test.ts: all 36 tests pass, including the 3 new COLUMN-absent cases. Branch coverage on the changed conditions (verified directly against coverage/lcov.info): the if (renameColumnMatch) check shows both arms hit (BRDA:170,35,0,3 / BRDA:170,35,1,517), if (dropColumnMatch) shows BRDA:179,36,0,64 / BRDA:179,36,1,453, and if (addColumnMatch) shows BRDA:182,37,0,189 / BRDA:182,37,1,264 — every branch this diff touches is exercised on both sides.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests. (N/A — no auth/session/CORS changes.)
  • API/OpenAPI/MCP behavior is updated and tested where needed. (N/A — no API/OpenAPI/MCP surface changed.)
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks. (N/A — no UI changes.)
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots. (N/A — no visible UI changes.)
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs. (N/A.)

Notes

  • Scoped exactly as the issue requires: no other ALTER TABLE variants (e.g. multi-column operations) were added, and no other parsing/collision-detection logic changed.

…sing (JSONbored#8368)

extractSchemaEvents' three ADD/DROP/RENAME regexes all required the literal
COLUMN keyword, but SQLite's actual ALTER TABLE grammar makes it optional
for all three forms -- ALTER TABLE t ADD x INTEGER, DROP x, and RENAME x TO
y are all valid without it. A migration using the terser syntax produced
zero SchemaEvents, invisible to detectColumnCollisions and silently
defeating the CI gate this parser backs. Makes COLUMN optional in all three
regexes; no other parsing or collision-detection logic changes. Adds test
cases for the COLUMN-absent form of all three statement types alongside
the existing COLUMN-present tests.
@philluiz2323
philluiz2323 requested a review from JSONbored as a code owner July 24, 2026 13:50
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.64%. Comparing base (af3340f) to head (4569d5d).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #8457       +/-   ##
===========================================
+ Coverage   59.66%   89.64%   +29.98%     
===========================================
  Files         791       98      -693     
  Lines       79319    22838    -56481     
  Branches    23952     3908    -20044     
===========================================
- Hits        47325    20473    -26852     
+ Misses      28250     2187    -26063     
+ Partials     3744      178     -3566     
Flag Coverage Δ
shard-1 100.00% <100.00%> (?)
shard-2 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/db/migration-column-extraction.ts 100.00% <100.00%> (ø)

... and 693 files with indirect coverage changes

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 24, 2026
@loopover-orb

loopover-orb Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Caution

🛑 LoopOver review result - reject/close recommended

Review updated: 2026-07-24 14:18:26 UTC

2 files · 1 AI reviewer · 1 blocker · CI green · dirty

🛑 Suggested Action - Reject/Close

Review summary
This is a narrow, well-targeted regex fix: all three ALTER TABLE regexes in `extractSchemaEvents` (src/db/migration-column-extraction.ts) now make the `COLUMN` keyword optional via `(?:COLUMN\s+)?`, matching SQLite's actual grammar for ADD/DROP/RENAME. The change correctly closes a real gap where the terser, equally-valid syntax previously produced zero SchemaEvents and silently defeated `detectColumnCollisions`. Tests exercise the exact non-obvious edge case (RENAME without COLUMN still correctly parses `RENAME color TO hue` rather than misparsing `color` as ambiguous), and all pre-existing COLUMN-present tests pass unmodified.

Nits — 3 non-blocking
  • The inline comment above the three regexes (src/db/migration-column-extraction.ts:166-169) is fairly long for a one-line rationale; could be trimmed since the git history/issue link already explains the 'why'.
  • No test covers a column name that could be confused with a keyword collision (e.g. an ADD without COLUMN followed immediately by a type keyword), though the existing regex behavior for extracting only `\w+` after ADD likely handles this fine — worth a quick sanity check but not blocking.
  • Consider adding one adversarial test case where a column name might overlap awkwardly with SQL syntax (e.g. `ALTER TABLE t ADD name TEXT` where 'name' could theoretically be misread) to lock in the greedy/non-greedy behavior of the new optional group long-term.

Why this is blocked

  • No linked issue detected: The PR cites an issue number, but it could not be verified as a currently open issue. — If this PR is intended to solve an issue, link it explicitly in the PR body.
📋 Copy for AI agents — paste into your coding agent
Fix the following blocker(s) from this PR review:

1. No linked issue detected: The PR cites an issue number, but it could not be verified as a currently open issue. — If this PR is intended to solve an issue, link it explicitly in the PR body.

Decision drivers

  • ❌ Code review — 1 blocker (1 reviewer)
  • ❌ Gate result — Blocking (Repo-configured hard blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8368
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 (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 1039 registered-repo PR(s), 613 merged, 126 issue(s).
Contributor context ✅ Confirmed Gittensor contributor philluiz2323; Gittensor profile; 1039 PR(s), 126 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff makes exactly the required regex change (\s+COLUMN\s+ to \s+(?:COLUMN\s+)?) in all three regexes as specified, and adds the three requested COLUMN-absent test cases while leaving other parsing/collision logic untouched.

Review context
  • Author: philluiz2323
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, JavaScript, MDX, TypeScript, CSS, Cuda, HTML, Kotlin
  • Official Gittensor activity: 1039 PR(s), 126 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
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.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 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 LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb

loopover-orb Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

LoopOver is closing this pull request on the maintainer's behalf (conflicts with the base branch — resolve and open a fresh PR; No linked issue detected). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed.

@loopover-orb loopover-orb Bot closed this Jul 24, 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

None yet

Development

Successfully merging this pull request may close these issues.

Migration column-extraction regexes require the literal COLUMN keyword, but SQLite doesn't

1 participant