Skip to content

Add make schema target loading 3 sample MySQL DBs#12

Merged
winebarrel merged 1 commit into
mainfrom
sample-databases
May 2, 2026
Merged

Add make schema target loading 3 sample MySQL DBs#12
winebarrel merged 1 commit into
mainfrom
sample-databases

Conversation

@winebarrel

Copy link
Copy Markdown
Owner

Summary

make schema loads three permissively-licensed MySQL sample databases into separate databases on the local server, ready for ad-hoc myschema dump / plan against realistic schemas.

Sample Source License Coverage
Chinook lerocha/chinook-database MIT 11 tables, FKs, indexes
employees datacharmer/test_db CC BY-SA 3.0 6 tables + 2 views
sakila dev.mysql.com BSD-style 16 tables + 7 views

Targets:

  • make schema — load all three
  • make load-chinook / make load-employees / make load-sakila — load one
  • make schema-drop — remove all three

Implementation notes

  • employees' source load_X.dump; lines are stripped with grep -v '^source ' before piping. mysql 8 rejects source outside interactive mode, and we don't need the data for schema management.
  • Once loaded:
    MYSCHEMA_DSN='root@tcp(127.0.0.1:3306)/Chinook'   ./myschema dump
    MYSCHEMA_DSN='root@tcp(127.0.0.1:3306)/employees' ./myschema dump
    MYSCHEMA_DSN='root@tcp(127.0.0.1:3306)/sakila'    ./myschema dump
  • Chinook and employees round-trip cleanly (dumpplan-- No changes).
  • Sakila fails round-trip because pingcap's parser does not recognise the geometry column type on address.location. Tracked in TODO.md.

Test plan

  • make schema loads all three (Chinook 11 tables, employees 6 tables + 2 views, sakila 16 tables + 7 views)
  • make schema-drop removes them
  • myschema dump against Chinook / employees / sakila works
  • myschema plan round-trip is clean for Chinook + employees
  • CI green on this PR (no behaviour change in source code; CI just needs to pass existing tests)

🤖 Generated with Claude Code

`make schema` loads:
- chinook (lerocha/chinook-database, MIT) — 11 tables, FKs, indexes
- employees (datacharmer/test_db, CC BY-SA 3.0) — 6 tables + 2 views
- sakila (dev.mysql.com, BSD-style) — 16 tables + 7 views

Each loader fetches the upstream artefact (curl for chinook + sakila,
git clone for employees), pipes the schema into the local mysql client,
and cleans up. `make schema-drop` removes all three.

Implementation notes:
- The employees dump uses `source load_X.dump;` to bring in row-data,
  but mysql 8 rejects `source` outside interactive mode and we don't
  need the data for schema management anyway. `grep -v '^source '`
  strips those lines before piping.
- Chinook and employees round-trip cleanly through dump → plan
  (no drift).
- Sakila currently fails to round-trip because pingcap's parser does
  not recognise the GEOMETRY column type used by `address.location`.
  Tracked in TODO.md.

AGENTS.md gets a docs section showing how to point myschema at each
sample DB; TODO.md ticks off the Makefile schema-target item and adds
the geometry-parser follow-up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@winebarrel winebarrel merged commit 8b156dd into main May 2, 2026
2 checks passed
@winebarrel winebarrel deleted the sample-databases branch May 2, 2026 03:26
@codecov

codecov Bot commented May 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 35.78%. Comparing base (16b5c8e) to head (fa7eb89).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #12   +/-   ##
=======================================
  Coverage   35.78%   35.78%           
=======================================
  Files          24       24           
  Lines        1520     1520           
=======================================
  Hits          544      544           
  Misses        864      864           
  Partials      112      112           

☔ 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.

winebarrel added a commit that referenced this pull request May 2, 2026
Three inline comments, all valid.

parser/directive.go
  - anyDirectivePattern now allows optional whitespace between the
    colon and the directive name. A formatting slip like
    `-- myschema: renamed-from old` previously didn't even match the
    pattern, so the directive was silently ignored. The per-directive
    regex (renameDirectivePattern) stays strict, so such lines turn
    into "malformed directive" errors at validation. (Copilot #1.)

diff/rename.go
  - applyTableRenames / applyColumnRenames / applyIndexRenames each
    pre-validate that no two desired entries declare the same
    RenameFrom source via new duplicate*RenameSource helpers. Today
    a stray duplicate produced a confusing "source ... not found"
    error after the first rename mutated current; now it surfaces
    a dedicated "source ... is referenced by multiple ..." error
    before any mutation. (Copilot #2.)

AGENTS.md
  - The "in scope" entry for renamed-from now correctly states that
    `RENAME INDEX` is MySQL 5.7+, only `RENAME COLUMN` is 8.0+.
    Project baseline is 8.0 (INVISIBLE indexes, CHECK constraints),
    so the 8.0-only RENAME COLUMN sits inside that envelope. The
    earlier "all 8.0+" wording was factually wrong. (Copilot #3.)

Tests
  - parser/directive_test.go: TestValidateDirectivesRejectsSpaceAfterColon
    covers the new validator behaviour for `-- myschema: name`.
  - diff/rename_test.go: TestDiffRenameDuplicateSourceErrors covers
    the duplicate-source guard for the column-rename path (table
    and index paths share the same shape and helper).

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