• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Python
  • License
    Other
  • Created over 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This utility parses PlantUML class diagram and generates SQL DDL for MySQL

plantuml2mysql

I liked plantuml tool for UML diagrams but use it also for visualizing structure of relational database. This script loads plantuml class diagram and generates DDL for MySQL SQL dialect. You may define primary keys with # prefix in field name (it means protected field in PlantUML) and define index fields with + (public field in PlantUML) prefix.

Field type noted after field name as is. Also you may use comments after --.

For example class definition:

@startuml

class dummy {
  Sample table.
  ==
  #id int(10) -- A comment
  field1 int(10)
  .. Comment line, ignored ..
  field2 varchar(128)
}

@enduml

will be converted to SQL:

CREATE TABLE IF NOT EXISTS `dummy` (
  id               INT(10) COMMENT 'A comment',
  field1           INT(10),
  field2           VARCHAR(128),
  PRIMARY KEY (id));

Text between class name and == is table description. The description of the table is mandatory. I was too lazy to check for absence of descriptions but not lazy to write them in each table of my databases.

A line starting with .. or __, used as a separator into a class definition, will be ignored.

The HTML markup in comments (after --) is stripped.

See below the result of a more complicated sample from database.plu:

database.png

    ./plantuml2mysql.py database.plu sampledb
    CREATE DATABASE sampledb CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;
    USE sampledb;                                                           
                                                                            
    CREATE TABLE IF NOT EXISTS `user` (                                       
      id               SERIAL,                                              
      login            VARCHAR(16),                                         
      mail             VARCHAR(64),                                         
      docsRef          INT(10) COMMENT 'referenced docs for a user',        
      created          INT(11),                                             
      sesid            INT(11),                                             
      PRIMARY KEY (id),                                                     
      INDEX (login),                                                        
      INDEX (mail)                                                          
    );                                                                      
                                                                            
    CREATE TABLE IF NOT EXISTS `session` (                                    
      id               SERIAL,                                              
      uid              INT(10) UNSIGNED,                                    
      remoteip         INT(10) UNSIGNED,                                    
      useragent        VARCHAR(255),                                        
      data             LONGTEXT COMMENT 'serialized session data',          
      lastseen         INT(11),                                             
      PRIMARY KEY (id),                                                     
      INDEX (uid),                                                          
      INDEX (lastseen)                                                      
    );                                                                      
                                                                            
    CREATE TABLE IF NOT EXISTS `docs` (                                       
      id               INT(10),                                             
      fid              INT(10) COMMENT 'link to a file',                    
      aunthorid        INT(10),                                             
      created          INT(11),                                             
      PRIMARY KEY (id, fid),                                                
      INDEX (aunthorid),                                                    
      INDEX (created)                                                       
    );                                                                      
                                                                            
    CREATE TABLE IF NOT EXISTS `files` (                                      
      id               SERIAL,                                              
      docId            INT(10),                                             
      title            VARCHAR(255),                                        
      path             VARCHAR(255),                                        
      hash             INT(32) UNSIGNED,                                    
      PRIMARY KEY (id),                                                     
      INDEX (docId)                                                         
    );                                                                      

Installation

The script not uses external dependencies. If you have installed Python 3 properly then just download plantuml2mysql.py to appropriate location and run as any other Python script.

Future

I just satisfied with this code as is but new features and fixes are welcome. Code is public domain.

Thank for contributions:

  • Benoรฎt Bailleux for a lot of features.

Mentions

Similar tools

More Repositories

1

m3u8

Parser and generator of M3U8-playlists for Apple HLS. Library for Go language. ๐ŸŽฆ
Go
1,225
star
2

hulk

HULK DoS tool ported to Go with some additional features.
Go
769
star
3

bcast

Broadcasting library for Go. Broadcast message of any type on a set of channels. WIP
Go
98
star
4

go-playground

GNU/Emacs mode that setup local Go playground for code snippets like play.golang.org or even better :)
Emacs Lisp
83
star
5

streamsurfer

Software for monitoring of HTTP video streams.
Go
82
star
6

rust-playground

GNU/Emacs mode that setup local playground for code snippets in Rust language.
Emacs Lisp
45
star
7

hlsprobe

Utility to probe Apple HLS streams.
Python
39
star
8

kiwi

Fast, structured, with filters and dynamic sinks. No levels. Logger & context keeper for Go language ๐Ÿฅ It smells like a mushroom.
Go
24
star
9

shift-shift

Xorg/Wayland keyboard layout switcher.
Go
15
star
10

russian-holidays

Russian holidays for GNU/Emacs calendar ๐Ÿ“†
Emacs Lisp
14
star
11

websocket-utils

Simple utils for testing websocket connections.
Go
5
star
12

reddit-clone-example

Example of realization of Reddit-like API with Go language.
Go
5
star
13

mpegts

Mpegts stream decoder
Go
3
star
14

gorg

Org-mode parser and generator for Golang
3
star
15

quickpic-cloud-linux-downloader

Download photos from the cloud that offered by Quickpic
Go
2
star
16

broadcast

The experiment
Go
2
star
17

pin-buffer

๐Ÿ“Pins buffer to current window in GNU/Emacs
Emacs Lisp
2
star
18

wtfm

Where's The Fucking Manual? (ok, let Write the Fabulous Manual)
Go
2
star
19

mysql-backup

Simple tool for backuping MySQL databases.
2
star
20

rule-mode

Emacs support for rule-based comments in code.
Emacs Lisp
2
star
21

slack-anything

Slack Anything offers additional ways for using Slack Chat
Go
2
star
22

keyboard

Alternative keyboard layouts. Colemacs layout for emacsers on unix.
PHP
2
star
23

go-loggers-comparison

Benchmarks of loggers for Go language.
Go
2
star
24

service

The service tree ๐ŸŒณ library for Go
Go
2
star
25

aeis

Ordering chaos in ~/.emacs.d.
Emacs Lisp
2
star
26

tw

Text Widgets library.
1
star
27

viewga

Experiments with desktop UI
1
star
28

quicksand

Quicksand โ€” website stress testing & DOS tool. Hulk' successor.
1
star
29

whereami

Where am I? โ€” executes actions based on your geographic place
1
star
30

webhotkey

URL shortener + HTTP proxy + DNS cache: swiss knife for webdeveloper.
1
star
31

apply

Apply the command to the project directories.
1
star
32

dotemacs

My emacs config.
Emacs Lisp
1
star
33

ergodox_configurator

JavaScript
1
star
34

portage-utils

Misc utils for Gentoo portage.
Python
1
star
35

perkeep-docker

Docker build for perkeep (calimstore).
Dockerfile
1
star
36

image-resize-service

The example of image resizing HTTP-service in Go
Go
1
star
37

randfs

Go library for generating random files/filenames/directories. For testing applications that needs work with massive number of files.
Go
1
star