drawdb-io / drawdb-io/drawdb

[BUG] DBML with field length definitions triggers SQL generation errors

Open
#1,051 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
39.5k
Forks
3.2k
Avg merge
10h 46m
Merged PRs (30d)
16

Description

**Describe the bug**
Create a generic-type diagram. After importing DBML, if the DBML contains field length specifications, the table column types will be displayed in the format such as VARCHAR(50). When exporting to MySQL, these types are recognized as custom types, causing an export error with an "undefined" prompt. After troubleshooting and fixing the problem, all column types in the exported SQL are unexpectedly converted to JSON.

**To Reproduce**
Steps to reproduce the behavior:
1. Navigate to File -> Import from -> DBML
2. Navigate to File -> Export SQL -> MySQL

**Expected behavior**
Can correctly display MySQL DDL

**Screenshots**

Image

Image

Image

**Desktop (please complete the following information):**
- OS: Windows 11
- Browser: chrome

**Additional context**
I have checked the DBML specification, which allows specifying field lengths in data types. [DBML column-settings](https://dbml.dbdiagram.io/docs#column-settings)

DBML
```
Table sys_user {
id bigint [pk, increment, note: "用户主键ID"]
username varchar(50) [unique, not null, note: "登录账号"]
password varchar(100) [not null, note: "加密密码"]
real_name varchar(30) [not null, note: "真实姓名"]
phone varchar(20) [note: "手机号"]
email varchar(100) [note: "邮箱"]
avatar varchar(255) [note: "头像地址"]
status tinyint [default: 1, note: "0禁用 1正常"]
role_id bigint [ref: > sys_role.id, note: "角色ID"]
create_at datetime [note: "创建时间", default: `now()`]
update_at datetime [note: "更新时间"]
}

Table sys_role {
id bigint [pk, increment]
role_name varchar(50) [not null, unique, note: "角色名称"]
role_code varchar(50) [not null, unique, note: "角色编码 admin/stock/sale"]
remark varchar(255) [note: "角色备注"]
create_at datetime
}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue through File -> Import from -> DBML, then File -> Export SQL -> MySQL using the supplied schema. Inspect the DBML import and MySQL export entry points to trace how VARCHAR(50)-style types are classified; done means the generated MySQL DDL preserves the field lengths and does not convert column types to JSON or show an undefined prompt.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mysql, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.