Database documentation generator
Project goal
The aim of this project is to generate database documentation from sql schema.
Supported databases
- MySQL
- MariaDB
Supported Output formats
- PNG, SVG image
- Plantuml raw text
- Json
Pre Installation
Installation
$ composer require pongee/database-to-documentation
or add it the your composer.json and make a composer update pongee/database-to-documentation.
Usage
In console
PNG export
$ php ./database-to-documentation mysql:image ./example/schema/sakila.sql > ./example/img/sakila.png
$ php ./database-to-documentation mysql:image --type png ./example/schema/sakila.sql > ./example/img/sakila.png
SVG export
$ php ./database-to-documentation mysql:image --type svg ./example/schema/sakila.sql > ./example/img/sakila.svg
Json export
$ php ./database-to-documentation mysql:json ./example/schema/sakila.sql
Plantuml export
$ php ./database-to-documentation mysql:plantuml ./example/schema/sakila.sql
PHP
Png export
<?php declare(strict_types=1);
use Pongee\DatabaseToDocumentation\DataObject\Sql\Database\Connection\ConnectionCollection;
use Pongee\DatabaseToDocumentation\Export\Plantuml;
use Pongee\DatabaseToDocumentation\Generator\ImageGenerator;
use Pongee\DatabaseToDocumentation\Parser\MysqlParser;
include __DIR__ . '/../../vendor/autoload.php';
$sqlSchema = '
CREATE TABLE IF NOT EXISTS `foo` (
`id` INT(10) UNSIGNED NOT NULL COMMENT "The id"
) ENGINE=innodb DEFAULT CHARSET=utf8;
';
$mysqlParser = new MysqlParser();
$plantumlExport = new Plantuml(file_get_contents(__DIR__ . '/../../src/Template/Plantuml/v1.twig'));
$forcedConnectionCollection = new ConnectionCollection();
$imageGenerator = new ImageGenerator(
'png',
__DIR__ . '/../../bin/plantuml.jar',
__DIR__ . '/../../tmp/'
);
$schema = $mysqlParser->run($sqlSchema, $forcedConnectionCollection);
print $imageGenerator->generate($plantumlExport->export($schema));
Json export
<?php declare(strict_types=1);
use Pongee\DatabaseToDocumentation\DataObject\Sql\Database\Connection\ConnectionCollection;
use Pongee\DatabaseToDocumentation\Export\Json;
use Pongee\DatabaseToDocumentation\Parser\MysqlParser;
include './vendor/autoload.php';
$sqlSchema = '
CREATE TABLE IF NOT EXISTS `foo` (
`id` INT(10) UNSIGNED NOT NULL COMMENT "The id"
) ENGINE=innodb DEFAULT CHARSET=utf8;
';
$mysqlParser = new MysqlParser();
$jsonExport = new Json();
$forcedConnectionCollection = new ConnectionCollection();
$schema = $mysqlParser->run($sqlSchema, $forcedConnectionCollection);
print $jsonExport->export($schema);
This will generate:
{ "tables": { "foo": { "columns": [ { "name": "id", "type": "INT", "typeParameters": [ "10" ], "otherParameters": "UNSIGNED NOT NULL", "comment": "The id" } ], "indexs": { "simple": [], "spatial": [], "fulltext": [], "unique": [] }, "primaryKey": [] } }, "connections": [] }