Skip to content

docs: document the FK + covering-index operational rule#35

Merged
winebarrel merged 3 commits into
mainfrom
document-fk-covering-index-rule
May 3, 2026
Merged

docs: document the FK + covering-index operational rule#35
winebarrel merged 3 commits into
mainfrom
document-fk-covering-index-rule

Conversation

@winebarrel

Copy link
Copy Markdown
Owner

Summary

Promote the "FK-implicit covering indexes look like drift" item from TODO.md / "Not yet implemented" to a deliberate operational rule: myschema will not auto-detect or auto-skip the implicit index MySQL creates for un-indexed FK columns. Desired SQL must spell out the matching KEY itself.

Why this is a rule, not a missing feature

A declarative tool works best when "what you wrote" is what gets applied. An implicit-index suppression heuristic (mirroring MySQL's reuse logic) would silently rewrite the user's intent and make the desired SQL non-self-describing. Requiring the explicit KEY is the same shape dump already emits, so dump → apply round-trips unaffected.

Changes

  • CAVEATS.md (new) — full rule with good / bad examples, the rationale, and the migration-from-existing-schema escape hatch (dump first).
  • AGENTS.md — drop the long "Not yet implemented" paragraph; replace with a short "Operational rules" pointer that references CAVEATS.md. Future operational rules go in the same place.
  • TODO.md — remove the "FK-implicit covering indexes look like drift" entry; no longer a planned fix.

No code changes.

Test plan

  • make lint (no Go changes; just confirming nothing else regressed)

🤖 Generated with Claude Code

Promote the FK + implicit-covering-index issue from "not yet
implemented" to a deliberate operational rule. myschema will not
auto-detect or auto-skip the implicit index that MySQL creates when
you declare a FK on un-indexed columns; the desired SQL must spell
out the matching `KEY` itself.

Rationale: a declarative tool works best when "what you wrote" is
what gets applied. An implicit-index suppression rule (mirroring
MySQL's reuse logic) would silently rewrite the user's intent.
Requiring the explicit `KEY` keeps desired SQL self-documenting and
matches what `dump` already emits, so `dump → apply` round-trips
unaffected.

Changes:
- New `CAVEATS.md` with the full rule, examples (good vs. bad), the
  reason myschema doesn't infer it, and the migration-from-existing-
  schema escape hatch (`dump` first).
- `AGENTS.md`: drop the long "Not yet implemented" paragraph; replace
  with a short "Operational rules" pointer that references CAVEATS.md.
- `TODO.md`: remove the "FK-implicit covering indexes look like drift"
  entry — no longer a planned fix.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 3, 2026 01:56
@codecov

codecov Bot commented May 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.40%. Comparing base (e50f32c) to head (6ef8938).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #35   +/-   ##
=======================================
  Coverage   73.40%   73.40%           
=======================================
  Files          27       27           
  Lines        2151     2151           
=======================================
  Hits         1579     1579           
  Misses        412      412           
  Partials      160      160           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

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 reclassifies myschema’s foreign-key implicit-index behavior from a planned fix to a documented operational rule, making the expectation explicit in repository docs instead of TODOs. It fits the codebase’s declarative-schema model by documenting that desired SQL must spell out FK covering indexes rather than relying on MySQL’s implicit index creation.

Changes:

  • Add a new CAVEATS.md document describing the FK covering-index rule, rationale, examples, and migration guidance.
  • Update AGENTS.md to point readers at CAVEATS.md and summarize the rule under operational constraints.
  • Remove the old FK-implicit-index item from TODO.md now that it is no longer considered a planned implementation gap.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
TODO.md Removes the FK implicit-index item from the outstanding work list.
CAVEATS.md Adds the canonical user-facing explanation of the FK covering-index rule.
AGENTS.md Replaces the old limitation note with a short operational-rule summary and pointer to CAVEATS.md.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread AGENTS.md Outdated
Comment thread AGENTS.md Outdated
Comment thread CAVEATS.md Outdated
Comment thread AGENTS.md Outdated
Four nits, all valid:

- testdata/plan/fk_implicit_index_drift.yml: header was telling
  maintainers to delete the fixture once the AGENTS.md "Not yet
  implemented" note disappeared — but this PR removed that note. Re-
  anchor the fixture as a permanent pin of the CAVEATS.md rule.
- AGENTS.md operational-rules summary said "explicit matching `KEY`",
  which narrows the actual rule (PRIMARY KEY / UNIQUE also count).
  Widen to "PRIMARY KEY / UNIQUE / KEY" so readers don't add a
  redundant secondary index when a PK already covers the FK.
- AGENTS.md summary also lost the operational nuance: an FK without
  covering index does not always make apply error — it surfaces as
  a `-- skipped: DROP INDEX` in plan by default, and only errors
  with 1553 if the user passes `--allow-drop=index`. Restore that
  detail.
- CAVEATS.md "Requiring an explicit `KEY`" had the same narrowing.
  Widen to "explicit covering index (PRIMARY KEY / UNIQUE / KEY)".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

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 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CAVEATS.md Outdated
CAVEATS.md "The rule only matters when you handwrite a CREATE TABLE
from scratch" was too narrow. myschema also accepts standalone
`ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY` in desired SQL (it's
listed in AGENTS.md "In scope (v1)"), and the same implicit-index
drift fires there too. Widen the wording so both shapes are covered.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

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 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@winebarrel winebarrel merged commit ce044af into main May 3, 2026
9 checks passed
@winebarrel winebarrel deleted the document-fk-covering-index-rule branch May 3, 2026 02:17
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.

2 participants