molay76/laravel-mysql2plantuml
Composer 安装命令:
composer require molay76/laravel-mysql2plantuml
包简介
convert mysql schema to plantuml
README 文档
README
TL;DR
php artisan dump:mysql2puml
/storage/ER以下にPlantUML製ER図が出力されます。
config
php artisan vendor:publish --provider=Mysql2PlantUml\Mysql2PlantUmlServiceProvider
設定ファイルが/config/以下にダンプされます。
以下の例では Mysql2PlantUml\app\Models\ValueObjects\Relation クラスのクラス定数を使っています。
composer require --dev でこのライブラリをインストールした場合、本番環境では存在しないクラスの参照でエラーが起きます。require --devする場合、クラス定数内で定義されてある文字列を直に設定ファイルに書き込んでください。
dist_dir
出力先のディレクトリを指定します。
'dist_dir' => 'storage/ER',
connection
information_schemaを指すようにデータベース接続先を指定します。
'connection' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE_INFORMATION_SCHEMA', 'information_schema'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter(
[
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]
) : [],
],
target_database
ER図に表現する対象のデータベース名を指定します。
'target_database' => env('DB_DATABASE'),
without_tables
/*
* ER図上に描かないテーブルを指定します
*/
'without_tables' => [
'migrations'
],
relation_type
多重度の表現方法を指定します。
'target_database' => Relation::FORMAT_NUM,
// or
'target_database' => Relation::FORMAT_CROW,
relations
テーブル間のリレーションとその図示を定義します。 何もなくとも外部キー制約を元にリレーションを図示します。
- from : puml上の左辺。テーブル名
- to : puml上の右辺。テーブル名
- relation : 両者の関係。定数は\Mysql2PlantUml\app\Models\ValueObjects\Relation::RELATION_TYPESを参照。
- direction : puml上の関係線の伸ばす方向。定数は\Mysql2PlantUml\app\Models\ValueObjects\Relation::DIRECTION_TYPESを参照。
- arrowLength : puml上の関係線の長さ。常に($arrowLength > 0) === true
'relations' => [
[
'from' => 'hoge',
'to' => 'fuga',
'relation' => Relation::MANY_MANDATORY_TO_ONE_MANDATORY,
'direction' => Relation::DIRECTION_LEFT,
'arrowLength' => 4,
],
[
'from' => 'foo',
'to' => 'bar',
'relation' => Relation::ONE_MANDATORY_TO_ONE_MANDATORY,
'direction' => Relation::DIRECTION_UP,
'arrowLength' => 4,
],
],
packages
PlantUML上で複数テーブルをパッケージとしてまとめます。
'packages' => [
'hogefuga' => [
'foo',
'bar'
],
'foobar' => [
'hoge',
'fuga'
]
]
sub_files
特定のテーブルのみのPlantUMLファイルを作ります。
'sub_files' => [
'hoge.puml' => [
'foo',
'hoge',
],
'fuga.puml' => [
'foo',
'bar',
'fuga',
],
],
example
sql
create table migrations
(
id int unsigned auto_increment
primary key,
migration varchar(255) not null,
batch int not null
)
collate = utf8mb4_unicode_ci;
create table tags
(
id bigint unsigned auto_increment
primary key,
title varchar(255) not null
)
collate = utf8mb4_unicode_ci;
create table task_tag
(
task_id bigint unsigned not null,
tag_id bigint unsigned not null,
constraint task_tag_custom_task_id_foreign
foreign key (task_id) references tasks (id),
constraint task_tag_tag_id_foreign
foreign key (tag_id) references tags (id)
)
collate = utf8mb4_unicode_ci;
create table tasks
(
id bigint unsigned auto_increment
primary key,
user_id bigint unsigned not null,
content varchar(255) not null,
constraint tasks_user_id_unique
unique (user_id),
constraint tasks_user_id_foreign
foreign key (user_id) references users (id)
on update cascade on delete cascade
)
collate = utf8mb4_unicode_ci;
create table users
(
id bigint unsigned auto_increment
primary key,
name varchar(255) not null
)
collate = utf8mb4_unicode_ci;
plantuml
@startuml
skinparam {
defaultFontName Monospaced
}
left to right direction
package dacapo_sample {
entity "migrations" as migrations {
+ id [PK] int(10) unsigned not null
migration varchar(255) not null
batch int(11) not null
}
entity "tags" as tags {
+ id [PK] bigint(20) unsigned not null
title varchar(255) not null
}
entity "task_tag" as task_tag {
# task_id [FK] [MUL] bigint(20) unsigned not null
# tag_id [FK] [MUL] bigint(20) unsigned not null
}
entity "tasks" as tasks {
+ id [PK] bigint(20) unsigned not null
# user_id [FK][UK] bigint(20) unsigned not null
content varchar(255) not null
}
entity "users" as users {
+ id [PK] bigint(20) unsigned not null
name varchar(255) not null
}
}
task_tag }o-- tasks
task_tag }o-- tags
tasks }o-- users
@enduml
```dacapo_sample_ER.svg
ER図(puml to svg)
molay76/laravel-mysql2plantuml 适用场景与选型建议
molay76/laravel-mysql2plantuml 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.91k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mysql」 「laravel」 「plantuml」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 molay76/laravel-mysql2plantuml 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 molay76/laravel-mysql2plantuml 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 molay76/laravel-mysql2plantuml 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Create UML class diagrams from your PHP source.
Database schema visualization
PlantUML class diagram generation based on pimcore class definitions
PHP module for MySql database
Wrap for UML generation by PlantUml on PHP
统计信息
- 总下载量: 2.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-06