Add tools/export_ddl.py — multi-table DDL with foreign keys - #40
Merged
Conversation
Graduates find.py's --ddl into a full exporter:
- resolves business terms (reusing find.resolve) to a set of entities -> tables
- derives real FOREIGN KEY constraints from the dictionary's relationship hints
("links to" / "references"); polymorphic (multi-target) refs and "collection
of" reverse relations handled correctly (column+comment / listed, not FK)
- surrogate-key modeling: FK columns become INTEGER referencing <table>_id
- dependency-ordered (topological) output so it loads under strict dialects
- --dialect sqlite|postgres|mysql; SQLite output self-validates
README pointer + CHANGELOG [Unreleased] added.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
cloud3000
added a commit
that referenced
this pull request
Jun 27, 2026
Note the multi-table DDL exporter with foreign keys (#40). Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Graduates
find.py's--ddlinto a fulltools/export_ddl.py: export amulti-table relational schema (with real foreign keys) for any set of business
terms.
How it works
find.resolve— a term (category/entity/alias) selects items → oneCREATE TABLEper entity.links to X(ERPNext) /references X(Odoo/Tryton) → single FKreferences X, Y, Z→ polymorphic, kept as a plain columncollection of X→ reverse relation, listed as a comment (not a column)INTEGERreferencing<target>_id, so the schema is internally consistent. FKs are emitted onlywhen the target table is part of the same export (or a self-reference);
otherwise the column is kept with an "external ref" comment.
dialects.
--dialect sqlite|postgres|mysql;--out FILE.Verified
work_order(single entity) andmanufacturing(37 tables, 59 FKs) bothvalidate by loading in SQLite.
manufacturing:FOREIGN KEY (bom_no) REFERENCES bom(bom_id), self-ref onamended_from,FK to
production_plan.(SQLite is self-validated; pg/mysql are rendered — no server to load-test here.)
CHANGELOG
[Unreleased]+ README pointer added;ci_checkgreen.🤖 Generated with Claude Code