Make database diagrams in DIA automatically

Continuing from yesterday’s post, I’ve written a utility in Python that reads an SQL schema and outputs a DIA file for it. As of now it is not designed to handle relations between tables. I have used it to create diagrams from SQL schemas written for MySQL. It should not be too hard to make it work with other database systems by changing the parsing code. The parsing is accomplished with regular expressions, which may be a little confusing but it seems to work OK on most cases tested.

For example, let’s say we have the following SQL schema:

create table post (
  id int(11) not null,
  title varchar(50) not null,
  contents varchar(500),
  date_posted datetime not null,
  primary key (id)
create table comment (
  id int(11) not null,
  contents varchar(500),
  post_id int(11) not null,
  primary key(id)

The automatically generated diagram is the following (after fixing the layout of the tables and inserting a relation between the two tables):

Sample database diagram

You can download the utility from here: Make database diagrams in DIA utility.


3 Responses to “Make database diagrams in DIA automatically”

  1. Tony Says:

    Thank you! I used it to convert postgreSQL and MySQL .sql files for asterisk realtime to DIA, worked perfectly!

  2. webmonarch1253 Says:

    FYI, when I run it with Python 3, I get an error.

    File “”, line 156
    print file_template % {‘tables’:tables_text}

    Running explicitly with python2 works!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: