Daniel Afonso Heisler
IT department - UNIVATES
There are few programs on Linux to convert UML diagrams into SQL instructions. This way, I decided to write a php class to read a DIA diagram and generate the correspondent SQL instructions to create DataBase.
DIA (http://hans.breuer.org/dia) is a gtk+ program to create diagrams. It can be used to draw many sort of diagrams, including UML diagrams. However, as the most of programs, DIA generates only the diagram, It doesn't export SQL instructions.
The dia2sql.php class is a tool that convert this UML diagram into SQL. As Dia files are saved in XML format, is possible to read these files and create a DataBase structure easily.
This first version supports only PostgreSQL.
In order to use the class the right way is needed to foolow some conventions during the diagram creation. This first version supports only classes (tables) and associations (references). You gotta save the diagram in XML format.
- The class name is always the table name.
- The table fields are inserted as attributes.
- The attributes (fields) can be:
'+' -> 'Public': Simple field.
'#' -> 'Protected': Primary key;
'-' -> 'Privated': Creates an individual index and another one grouped with all others marked with this option.
' ' -> 'Implementation': Creates a unique index grouped with another ones marked with this option and one index to each individual field;
- The Option Class Scope is used to define whether the field is a sequence or not;
- The references are done with "Associate to UML" option. You must link two fields of tables and show the origin and the target of the relation. It's important to stablish the link of the fields exactly at the points near of each field.
Inside the package, there is a file called example.dia that can be either edited by DIA or converted into SQL instructions. In order to execute the program, type:
# php example.php
A "sql" directory will be created with respective files containing the Database creation instructions.