Skip to content

Add tools/export_ddl.py — multi-table DDL with foreign keys - #40

Merged
cloud3000 merged 1 commit into
mainfrom
export-ddl-tool
Jun 27, 2026
Merged

Add tools/export_ddl.py — multi-table DDL with foreign keys#40
cloud3000 merged 1 commit into
mainfrom
export-ddl-tool

Conversation

@cloud3000

Copy link
Copy Markdown
Owner

Summary

Graduates find.py's --ddl into a full tools/export_ddl.py: export a
multi-table relational schema (with real foreign keys) for any set of business
terms.

How it works

  • Reuses find.resolve — a term (category/entity/alias) selects items → one
    CREATE TABLE per entity.
  • Foreign keys derived from the dictionary's relationship hints:
    • links to X (ERPNext) / references X (Odoo/Tryton) → single FK
    • multi-target FHIR references X, Y, Z → polymorphic, kept as a plain column
    • collection of X → reverse relation, listed as a comment (not a column)
  • Surrogate-key modeling: a FK column becomes INTEGER referencing
    <target>_id, so the schema is internally consistent. FKs are emitted only
    when the target table is part of the same export (or a self-reference);
    otherwise the column is kept with an "external ref" comment.
  • Dependency-ordered (topological sort) output so it loads under strict
    dialects.
  • --dialect sqlite|postgres|mysql; --out FILE.

Verified

  • work_order (single entity) and manufacturing (37 tables, 59 FKs) both
    validate by loading in SQLite.
  • Cross-entity FKs resolve, e.g. within manufacturing:
    FOREIGN KEY (bom_no) REFERENCES bom(bom_id), self-ref on amended_from,
    FK to production_plan.
  • postgres/mysql render correct types (SERIAL/TIMESTAMP, AUTO_INCREMENT/TINYINT).
    (SQLite is self-validated; pg/mysql are rendered — no server to load-test here.)

CHANGELOG [Unreleased] + README pointer added; ci_check green.

🤖 Generated with Claude Code

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
cloud3000 merged commit 576b268 into main Jun 27, 2026
1 check passed
@cloud3000
cloud3000 deleted the export-ddl-tool branch June 27, 2026 20:30
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>
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