Database modeling

+6 votes
asked Feb 22, 2013 in Wanted features by anonymous
Hi, I wonder how I can use this great tool to draw database modelling. The closest feature I can think of at the moment is object diagram. However it does not support 'index', 'unique', 'primary key', 'compound primary key' and the like. Thanks

3 Answers

+5 votes
answered Feb 22, 2013 by plantuml (294,960 points)

Some users are using class diagram, and preprocessing facilities. http://plantuml.sourceforge.net/preprocessing.html
You can define then something like :

@startuml
!define table(x) class x << (T,#FFAAAA) >>
!define primary_key(x) <u>x</u>
hide methods
hide stereotypes

table(FOO1) {
  primary_key(FIELD1)
  FIELD2
}
@enduml

commented Feb 22, 2013 by oradoe (100 points)
Hi, thank you very much. I really appreciate this answer. One thing remains, how can I link attributes across class? Currently I have to do in package and class level.


@startuml

package user {
  class user.id <pk>
  class email <unique>
  class name <index>
}

package class {
  class id
  class uid "1" - "n" user.id
}

package cpk {
  cid - pid: cpk
}

@enduml
commented Feb 22, 2013 by plantuml (294,960 points)
Unfortunatly, this is something you cannot do with PlantUML today.
This is theorically possible (because GraphViz allows this, see http://www.graphviz.org/doc/info/html1.gif on http://www.graphviz.org/doc/info/shapes.html).
So, in future version, maybe PlantUML will allow to link attributes, but not on the short term.
Regards,
commented Jun 29, 2016 by plantuml (294,960 points)
With last beta https://dl.dropboxusercontent.com/u/13064071/plantuml.jar

You can now have:

@startuml
class Foo {
+ field1
+ field2
}

class Bar {
+ field3
+ field4
}

Foo::field1 --> Bar::field3 : foo
Foo::field2 --> Bar::field4 : bar
@enduml

Note that this is still a beta version, so it may not work/crash in some case.
Feedback welcome!
0 votes
answered Jun 27, 2016 by axel (140 points)

I was need similar feature for RDBMS and used class diagrams. IMO with simple conventions (like usage of protected and public fields of class diagram for PKs and indexes) it good enough for visualizing.

@startuml

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

@enduml


Additionally for generating SQL DDL from PlantUML diagram sources I created simple Python script (for MySQL in my case) https://github.com/grafov/plantuml2mysql. It helpes me maintain real database with single source in format of class diagram. I think it may be easily adapted for other RDBMS as well.

commented Jun 27, 2016 by plantuml (294,960 points)
We are thinking about allowing this kind of diagrams (this is not working yet)

@startuml
class Foo {
+ field1
+ field2
}

class Bar {
+ field3
+ field4
}

Foo::field1 --> Bar::field2 : link between fields
@enduml

However, this needs some works...

About primary key, you can use the sprite feature (see http://plantuml.com/sprite.html )

So that you can have something like:

http://www.plantuml.com/plantuml/uml/JOxVQuCm7CJVyrTy7_RGmdI9zjTW7NILEboTPIiJ6QD4pLmWIJNQJXtxtnSOGb_kkFlSmzMbvWs3AsEIwWxUoRmbpWsPzH-GHjNPPGIxU1syz3jrksaFpt4oLnDM1Uu-g6VH6vsM-zApfermasxpw5iJhwvMaOeB-XsNMECddnRUoG-JC6ZJK3-q_NON72BiOumGoWIjQyXFKdRmWm1UgIm5WuQcWjacBvT6xePtzy1LCo9uR4gU3m4i2rQG7QLagZ7aapEHaukfRSFwduBWYbq3BzHHizo0OUx0cUhiY-eHSHPZzFi7
commented Oct 7, 2016 by anonymous
I've seen you introduced that feature in V8045, unfortunately i'm using the idea plugin which is still on V8043.
Can i upgrade myself or do you have an estimate when a new version will be available?
commented Oct 7, 2016 by plantuml (294,960 points)
You may try to upgrade yourself. Change plantuml.jar should to the trick (although I do not know how to do it on the idea plugin).
+1 vote
answered Dec 2, 2017 by Anthony-Gaudino (5,720 points)

It has been implemented, see https://github.com/plantuml/plantuml/pull/31 , but it's still not documented.

Also see https://gist.github.com/QuantumGhost/0955a45383a0b6c0bc24f9654b3cb561 for a hack to do it using class diagrams.

...