Skip to content

Add database migration generator and Mermaid ER diagram generator - #8

Draft
hatcheric950 wants to merge 1 commit into
mainfrom
claude/database-migration-er-generator-asxka
Draft

Add database migration generator and Mermaid ER diagram generator#8
hatcheric950 wants to merge 1 commit into
mainfrom
claude/database-migration-er-generator-asxka

Conversation

@hatcheric950

Copy link
Copy Markdown
Owner

Summary

  • Flyway migration generator (db_tools/migration_generator.py): diffs two JPA entity Java source files and emits ALTER TABLE DDL compatible with Flyway versioned migrations. Detects added/dropped columns, renames, type/nullability changes, and unique constraint changes. Handles fully-qualified type names (java.math.BigDecimal) and both multi-line and same-line annotation styles.
  • Mermaid ER diagram generator (db_tools/er_diagram_generator.py): parses SQL CREATE TABLE statements (MySQL/PostgreSQL/SQLite, backtick/quote/bracket-quoted identifiers, table-level PK/FK/UNIQUE constraints) and produces a erDiagram Mermaid block with PK/FK/UK markers and relationship lines.
  • CLI (db_tools_cli.py): migrate and er sub-commands with --output flag support.
  • Examples: User entity v1→v2 diff pair and a 4-table e-commerce schema (users, orders, order_items, products).
  • Tests: 58 unit tests, all passing.

Test plan

  • python -m pytest tests/ -v — all 58 tests green
  • python db_tools_cli.py migrate --old examples/entities/User_v1.java --new examples/entities/User_v2.java — produces correct ALTER TABLE users DDL
  • python db_tools_cli.py er --sql examples/schema.sql — produces valid 4-table Mermaid erDiagram with FK relationships
  • python db_tools_cli.py er --sql examples/schema.sql --output diagram.md — writes fenced Mermaid block to file

https://claude.ai/code/session_012vCaNNL7Z6pJEBbjS8d8nQ


Generated by Claude Code

Two Python CLI tools for database developer productivity:
- `db_tools/migration_generator.py`: diffs two JPA entity Java files and
  emits Flyway-compatible ALTER TABLE DDL (add/drop/rename/modify columns,
  unique constraint changes). Handles fully-qualified type names and both
  multi-line and same-line annotation styles.
- `db_tools/er_diagram_generator.py`: parses SQL CREATE TABLE statements
  (MySQL/PostgreSQL/SQLite syntax, backtick/quote-quoted identifiers,
  table-level PK/FK/UNIQUE constraints) and produces a Mermaid erDiagram block.
- `db_tools_cli.py`: argparse CLI with `migrate` and `er` sub-commands.
- `examples/`: User entity v1/v2 pair and a 4-table e-commerce schema.
- `tests/`: 58 unit tests covering all public functions (100% pass).

https://claude.ai/code/session_012vCaNNL7Z6pJEBbjS8d8nQ
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