Skip to content

Intellij IDEA plugin- MySQL/PostgreSQL DDL and PlantUML convert to each other.

License

Notifications You must be signed in to change notification settings

xwsg/plantuml2ddl

Repository files navigation

PlantUML2DDL

Intellij IDEA plugin PlantUML2DDL for MySQL/PostgreSQL DDL and PlantUML Entity Relationship Diagram convert to each other.

Installation

Install this plugin both from plugin marketplace and from disk. Releases page

Defining Symbol

Symbol Explain Example
# PRIMARY KEY #id : bigint(20)
<<pk>> PRIMARY KEY id : bigint(20) <<pk>>
* NOT NULL *type : tinyint(4)
<<notnull>> NOT NULL type : tinyint(4) <<notnull>>
<<generated>> AUTO_INCREMENT #id : bigint(20) <<generated>>
<<default:{DEFAULT_VALUE}>> DEFAULT {DEFAULT_VALUE} *name : varchar(50) <<default:'anonymous'>>
type : tinyint(4) <<default:0>>
--{COLUMN_COMMENT} column COMMENT '{COLUMN_COMMENT}' *name : varchar(50) <<default:'anonymous'>> --user name
{TABLE_COMMENT}
--/../==/__
table COMMENT '{TABLE_COMMENT}' entity "tbl_user" {
  table for user
  --
}
entity "tbl_user" {
  table for user
  ..
}
entity "tbl_user" {
  table for user
  ==
}
entity "tbl_user" {
  table for user
  __
}

Usage

Convert PlantUML to DDL

  1. Open a PlantUML file
  2. In this file, Right-click or Alt-Insert
  3. Select Generate -> PlantUML -> MySQL or PlantUML -> PostgreSQL.

For example: mysql_sample.puml

@startuml aaa

' hide the spot
hide circle

' avoid problems with angled crows feet
skinparam linetype ortho

entity "tbl_user" as user {
  table for user
  --
  #id : bigint(20) <<generated>>
  --
  *type : tinyint(4) <<default:0>> --user type: 0-pc,1-mobile
  *name : varchar(50) <<default:'anonymous'>> -- user name
  description : varchar(200) <<default:'some string'>> --user description
}

entity "tbl_order" as order {
  table for order
  ==
  #id : bigint(20) <<generated>>
  --
  * **order_number** : varchar(20)  <<default:'0'>> -- order number
  *user_id : bigint(20) <<FK>> <<default:0>> -- user id
  *item_id: bigint(20) <<FK>> <<default:0>> -- item id
}

entity "tbl_item" as item {
  table for item
  ..
  #id : bigint(20)  <<generated>>
  --
  title : varchar(50)  <<default: 'wahaha'>> <<notnull>> -- item title
  *price : int(11) <<default: 0>> -- item price
}

user }|..|{ order
item }|..|{ order

@enduml

plantuml2ddl

In the current directory, will generate a file mysql_sample_{yyyyMMddHHmmss}.sql:

create table if not exists `tbl_user` (
    `id` bigint(20) not null auto_increment,
    `type` tinyint(4) not null default 0 comment 'user type: 0-pc,1-mobile',
    `name` varchar(50) not null default 'anonymous' comment 'user name',
    `description` varchar(200) default 'some string' comment 'user description',
    primary key (`id`)
) comment 'table for user';

create table if not exists `tbl_order` (
    `id` bigint(20) not null auto_increment,
    `order_number` varchar(20) not null default '0' comment 'order number',
    `user_id` bigint(20) not null default 0 comment 'user id',
    `item_id` bigint(20) not null default 0 comment 'item id',
    primary key (`id`)
) comment 'table for order';

create table if not exists `tbl_item` (
    `id` bigint(20) not null auto_increment,
    `title` varchar(50) not null default 'wahaha' comment 'item title',
    `price` int(11) not null default 0 comment 'item price',
    primary key (`id`)
) comment 'table for item';

Convert DDL to PlantUML

  1. Open a DDL file
  2. In this file, Right-click or Alt-Insert
  3. Select Generate -> MySQL -> PlantUML or PostgreSQL -> PlantUML.

About

Intellij IDEA plugin- MySQL/PostgreSQL DDL and PlantUML convert to each other.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages