Skip to content

Add erdn sql command for SQL DDL export with multi-DBMS support#6

Merged
nemorize merged 1 commit into
mainfrom
copilot/add-sql-export-command
Apr 14, 2026
Merged

Add erdn sql command for SQL DDL export with multi-DBMS support#6
nemorize merged 1 commit into
mainfrom
copilot/add-sql-export-command

Conversation

Copilot AI commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Adds a new sql subcommand that generates SQL DDL from an .erdn schema, targeting MySQL, PostgreSQL, MSSQL, Oracle, or SQLite via --dbms.

New command

erdn sql <schema.erdn> [--dbms <mysql|postgresql|mssql|oracle|sqlite>] [--out <file.sql>]

Defaults to mysql. Output file defaults to <schema>.sql.

What gets generated

  • CREATE TABLE with DBMS-appropriate column types
  • PRIMARY KEY table constraints
  • Auto-increment per dialect: AUTO_INCREMENT (MySQL), IDENTITY(1,1) (MSSQL), GENERATED ALWAYS AS IDENTITY (PostgreSQL/Oracle), INTEGER PRIMARY KEY AUTOINCREMENT (SQLite)
  • CREATE INDEX for indexed columns
  • Foreign keys from link declarations — ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY for most DBMSes; inline FOREIGN KEY table constraints for SQLite (with PRAGMA foreign_keys = ON)

Type mapping highlights

erdn type MySQL PostgreSQL MSSQL Oracle SQLite
bool TINYINT(1) BOOLEAN BIT NUMBER(1) INTEGER
varchar(n) VARCHAR(n) VARCHAR(n) NVARCHAR(n) VARCHAR2(n) TEXT
text TEXT TEXT NVARCHAR(MAX) CLOB TEXT
bigint BIGINT BIGINT BIGINT NUMBER(19) INTEGER
uuid CHAR(36) UUID UNIQUEIDENTIFIER CHAR(36) TEXT

NOW() defaults are translated per dialect (GETDATE() for MSSQL, SYSDATE for Oracle, CURRENT_TIMESTAMP for SQLite). Unknown types pass through uppercased.

Changes

  • internal/sqlexport/sqlexport.go — new package; all generation logic isolated here
  • internal/sqlexport/sqlexport_test.go — tests covering all five DBMSes, type mappings, self-referential links, default value translation, indexes, and FK output
  • cmd/erdn/main.go — wires runSQL() into the subcommand dispatcher
  • README.md / website/guide.md — documents the new command and DBMS table

@github-actions

Copy link
Copy Markdown

🗂 ER Diagram Render

Tests passedgo test ./...

advanced.erdn

  • SVG rendered successfully (34.1 KB)

blog.erdn

  • SVG rendered successfully (85.4 KB)

cjk.erdn

  • SVG rendered successfully (80.6 KB)

ecommerce.erdn

  • SVG rendered successfully (104.8 KB)

simple.erdn

  • SVG rendered successfully (16.0 KB)

📦 Download diagrams — open the workflow run and expand Artifacts to download the SVG archive.

@nemorize nemorize marked this pull request as ready for review April 14, 2026 00:04
@nemorize nemorize merged commit de3b74f into main Apr 14, 2026
2 checks passed
@nemorize nemorize deleted the copilot/add-sql-export-command branch April 14, 2026 00:04
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