diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 30c6280..aa55e17 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,11 +6,10 @@ on: tags: ['[0-9]+.[0-9]+.[0-9]+'] env: - IMAGE: ghcr.io/pongee/database-schema-visualization + IMAGE: pongeepublic/database-schema-visualization permissions: contents: read - packages: write jobs: build: @@ -35,9 +34,8 @@ jobs: - uses: docker/login-action@v4 with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + username: ${{ vars.DOCKER_HUB_USERNAME_FOR_GITHUB_DATABASE_SCHEMA_VISUALIZATION }} + password: ${{ secrets.DOCKER_HUB_PASSWORD_FOR_GITHUB_DATABASE_SCHEMA_VISUALIZATION }} - id: meta uses: docker/metadata-action@v6 @@ -81,9 +79,8 @@ jobs: - uses: docker/login-action@v4 with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + username: ${{ vars.DOCKER_HUB_USERNAME_FOR_GITHUB_DATABASE_SCHEMA_VISUALIZATION }} + password: ${{ secrets.DOCKER_HUB_PASSWORD_FOR_GITHUB_DATABASE_SCHEMA_VISUALIZATION }} - id: meta uses: docker/metadata-action@v6 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c705ef..38bf4a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [5.1.0] - 2026-07-28 +### Changed +- Markdown output is shifted down one heading level — a `## Tables` top heading, an `h3` heading per table and `h4` section headings (Columns, Primary Key, Indexes, …) instead of `# Schema` / `h2` / `h3` — so the dump embeds cleanly under a document title +- PlantUML tables now carry a `«table»` stereotype label +- PlantUML template colors are set through the `$table_border_color` / `$table_background_color` variables using the `?=` default-assignment operator, replacing the `TABLE_BORDER_COLOR` / `TABLE_BACKGROUND_COLOR` `!define`s +- Image rendering streams the diagram through PlantUML's `--pipe` mode (stdin to stdout) instead of writing a temporary source and image file, so no `tmp/` working directory is needed +- The Markdown exporter returns the rendered template unchanged, dropping the leading-whitespace strip, blank-line collapsing and trailing-newline normalization (matching the PlantUML exporter) + ## [5.0.0] - 2026-07-27 ### Added - Markdown export (`mysql:markdown` command and `Export\Markdown`) listing tables, columns, keys, indexes and connections, driven by a customizable Twig template (`src/Template/Markdown/v1.twig`) diff --git a/README.md b/README.md index 408d6e9..14c0a17 100644 --- a/README.md +++ b/README.md @@ -61,23 +61,23 @@ Output: ![Example output](example/output/sakila/sakila.png?raw=true "Output") ### Docker -The image is published to the GitHub Container Registry, built for both `linux/amd64` and `linux/arm64`. +The image is published to Docker Hub, built for both `linux/amd64` and `linux/arm64`. ```bash -$ docker pull ghcr.io/pongee/database-schema-visualization:latest +$ docker pull pongeepublic/database-schema-visualization:latest ``` Mount your schema into the container and pass the same command and options as on the CLI: ```bash $ docker run --rm -v "$PWD/schema.sql:/app/schema.sql" \ - ghcr.io/pongee/database-schema-visualization mysql:image --type png schema.sql > diagram.png + pongeepublic/database-schema-visualization mysql:image --type png schema.sql > diagram.png ``` List the available commands: ```bash -$ docker run --rm ghcr.io/pongee/database-schema-visualization list +$ docker run --rm pongeepublic/database-schema-visualization list ``` ### PHP @@ -89,6 +89,7 @@ $ docker run --rm ghcr.io/pongee/database-schema-visualization list use Pongee\DatabaseSchemaVisualization\DataObject\Sql\Database\Connection\ConnectionCollection; use Pongee\DatabaseSchemaVisualization\Export\Plantuml; use Pongee\DatabaseSchemaVisualization\Generator\ImageGenerator; +use Pongee\DatabaseSchemaVisualization\Generator\ImageType; use Pongee\DatabaseSchemaVisualization\Parser\MysqlParser; include __DIR__ . '/../../vendor/autoload.php'; @@ -99,17 +100,15 @@ $sqlSchema = ' ) ENGINE=innodb DEFAULT CHARSET=utf8; '; -$sqlParser = new MysqlParser(); -// $cqlParser = new \Pongee\DatabaseSchemaVisualization\Parser\CassandraParser(); +$parser = new MysqlParser(); // or CassandraParser(), MariadbParser(); $plantumlExport = new Plantuml(file_get_contents(__DIR__ . '/../../src/Template/Plantuml/v1.twig')); $forcedConnectionCollection = new ConnectionCollection(); $imageGenerator = new ImageGenerator( - 'png', - __DIR__ . '/../../bin/plantuml-mit-1.2026.6.jar', - __DIR__ . '/../../tmp/' + ImageType::Png, + __DIR__ . '/../../bin/plantuml-mit-1.2026.6.jar' ); -$schema = $sqlParser->run($sqlSchema, $forcedConnectionCollection); +$schema = $parser->run($sqlSchema, $forcedConnectionCollection); print $imageGenerator->generate($plantumlExport->export($schema)); ``` @@ -129,11 +128,11 @@ $sqlSchema = ' ) ENGINE=innodb DEFAULT CHARSET=utf8; '; -$mysqlParser = new MysqlParser(); +$parser = new MysqlParser(); $jsonExport = new Json(); $forcedConnectionCollection = new ConnectionCollection(); -$schema = $mysqlParser->run($sqlSchema, $forcedConnectionCollection); +$schema = $parser->run($sqlSchema, $forcedConnectionCollection); print $jsonExport->export($schema); ``` @@ -187,11 +186,11 @@ $sqlSchema = ' ) ENGINE=innodb DEFAULT CHARSET=utf8; '; -$mysqlParser = new MysqlParser(); +$parser = new MysqlParser(); $markdownExport = new Markdown(file_get_contents('./src/Template/Markdown/v1.twig')); $forcedConnectionCollection = new ConnectionCollection(); -$schema = $mysqlParser->run($sqlSchema, $forcedConnectionCollection); +$schema = $parser->run($sqlSchema, $forcedConnectionCollection); print $markdownExport->export($schema); ``` diff --git a/example/output/airportdb/airportdb.json b/example/output/airportdb/airportdb.json new file mode 100644 index 0000000..38e6159 --- /dev/null +++ b/example/output/airportdb/airportdb.json @@ -0,0 +1,1458 @@ +{ + "tables": { + "airline": { + "columns": [ + { + "name": "airline_id", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "iata", + "type": "char", + "typeParameters": [ + "2" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "airlinename", + "type": "varchar", + "typeParameters": [ + "30" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "base_airport", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "base_airport" + ], + "otherParameters": "", + "name": "base_airport_idx" + } + ], + "spatial": [], + "fulltext": [], + "unique": [ + { + "columns": [ + "iata" + ], + "otherParameters": "", + "name": "iata_unq" + } + ] + }, + "primaryKey": { + "columns": [ + "airline_id" + ], + "otherParameters": "" + } + }, + "airplane": { + "columns": [ + { + "name": "airplane_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "capacity", + "type": "mediumint", + "typeParameters": [], + "otherParameters": "unsigned NOT NULL", + "comment": "" + }, + { + "name": "type_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "airline_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "type_id" + ], + "otherParameters": "", + "name": "type_id" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "airplane_id" + ], + "otherParameters": "" + } + }, + "airplane_type": { + "columns": [ + { + "name": "type_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "identifier", + "type": "varchar", + "typeParameters": [ + "50" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "description", + "type": "text", + "typeParameters": [], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [], + "fulltext": [ + { + "columns": [ + "identifier", + "description" + ], + "otherParameters": "", + "name": "description_full" + } + ], + "unique": [] + }, + "primaryKey": { + "columns": [ + "type_id" + ], + "otherParameters": "" + } + }, + "airport": { + "columns": [ + { + "name": "airport_id", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "iata", + "type": "char", + "typeParameters": [ + "3" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "icao", + "type": "char", + "typeParameters": [ + "4" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "name", + "type": "varchar", + "typeParameters": [ + "50" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "name" + ], + "otherParameters": "", + "name": "name_idx" + }, + { + "columns": [ + "iata" + ], + "otherParameters": "", + "name": "iata_idx" + } + ], + "spatial": [], + "fulltext": [], + "unique": [ + { + "columns": [ + "icao" + ], + "otherParameters": "", + "name": "icao_unq" + } + ] + }, + "primaryKey": { + "columns": [ + "airport_id" + ], + "otherParameters": "" + } + }, + "airport_geo": { + "columns": [ + { + "name": "airport_id", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "name", + "type": "varchar", + "typeParameters": [ + "50" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "city", + "type": "varchar", + "typeParameters": [ + "50" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "country", + "type": "varchar", + "typeParameters": [ + "50" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "latitude", + "type": "decimal", + "typeParameters": [ + "11", + "8" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "longitude", + "type": "decimal", + "typeParameters": [ + "11", + "8" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "geolocation", + "type": "point", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [ + { + "columns": [ + "geolocation" + ], + "otherParameters": "", + "name": "geolocation_spt" + } + ], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "airport_id" + ], + "otherParameters": "" + } + }, + "airport_reachable": { + "columns": [ + { + "name": "airport_id", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "hops", + "type": "int", + "typeParameters": [], + "otherParameters": "DEFAULT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "airport_id" + ], + "otherParameters": "" + } + }, + "booking": { + "columns": [ + { + "name": "booking_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "flight_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "seat", + "type": "char", + "typeParameters": [ + "4" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "passenger_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "price", + "type": "decimal", + "typeParameters": [ + "10", + "2" + ], + "otherParameters": "NOT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "flight_id" + ], + "otherParameters": "", + "name": "flight_idx" + }, + { + "columns": [ + "passenger_id" + ], + "otherParameters": "", + "name": "passenger_idx" + } + ], + "spatial": [], + "fulltext": [], + "unique": [ + { + "columns": [ + "flight_id", + "seat" + ], + "otherParameters": "", + "name": "seatplan_unq" + } + ] + }, + "primaryKey": { + "columns": [ + "booking_id" + ], + "otherParameters": "" + } + }, + "employee": { + "columns": [ + { + "name": "employee_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "firstname", + "type": "varchar", + "typeParameters": [ + "100" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "lastname", + "type": "varchar", + "typeParameters": [ + "100" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "birthdate", + "type": "date", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "sex", + "type": "char", + "typeParameters": [ + "1" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "street", + "type": "varchar", + "typeParameters": [ + "100" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "city", + "type": "varchar", + "typeParameters": [ + "100" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "zip", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "country", + "type": "varchar", + "typeParameters": [ + "100" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "emailaddress", + "type": "varchar", + "typeParameters": [ + "120" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "telephoneno", + "type": "varchar", + "typeParameters": [ + "30" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "salary", + "type": "decimal", + "typeParameters": [ + "8", + "2" + ], + "otherParameters": "DEFAULT NULL", + "comment": "" + }, + { + "name": "username", + "type": "varchar", + "typeParameters": [ + "20" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "password", + "type": "char", + "typeParameters": [ + "32" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "department", + "type": "enum", + "typeParameters": [ + "Marketing", + "Buchhaltung", + "Management", + "Logistik", + "Flugfeld" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [], + "fulltext": [], + "unique": [ + { + "columns": [ + "username" + ], + "otherParameters": "", + "name": "user_unq" + } + ] + }, + "primaryKey": { + "columns": [ + "employee_id" + ], + "otherParameters": "" + } + }, + "flight": { + "columns": [ + { + "name": "flight_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "flightno", + "type": "char", + "typeParameters": [ + "8" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "from", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "to", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "departure", + "type": "datetime", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "arrival", + "type": "datetime", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "airline_id", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "airplane_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "from" + ], + "otherParameters": "", + "name": "from_idx" + }, + { + "columns": [ + "to" + ], + "otherParameters": "", + "name": "to_idx" + }, + { + "columns": [ + "departure" + ], + "otherParameters": "", + "name": "departure_idx" + }, + { + "columns": [ + "arrival" + ], + "otherParameters": "", + "name": "arrivals_idx" + }, + { + "columns": [ + "airline_id" + ], + "otherParameters": "", + "name": "airline_idx" + }, + { + "columns": [ + "airplane_id" + ], + "otherParameters": "", + "name": "airplane_idx" + }, + { + "columns": [ + "flightno" + ], + "otherParameters": "", + "name": "flightno" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "flight_id" + ], + "otherParameters": "" + } + }, + "flight_log": { + "columns": [ + { + "name": "flight_log_id", + "type": "int", + "typeParameters": [], + "otherParameters": "unsigned NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "log_date", + "type": "datetime", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "user", + "type": "varchar", + "typeParameters": [ + "100" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "flight_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "flightno_old", + "type": "char", + "typeParameters": [ + "8" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "flightno_new", + "type": "char", + "typeParameters": [ + "8" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "from_old", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "to_old", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "from_new", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "to_new", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "departure_old", + "type": "datetime", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "arrival_old", + "type": "datetime", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "departure_new", + "type": "datetime", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "arrival_new", + "type": "datetime", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "airplane_id_old", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "airplane_id_new", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "airline_id_old", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "airline_id_new", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "comment", + "type": "varchar", + "typeParameters": [ + "200" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "flight_id" + ], + "otherParameters": "", + "name": "flight_log_ibfk_1" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "flight_log_id" + ], + "otherParameters": "" + } + }, + "flightschedule": { + "columns": [ + { + "name": "flightno", + "type": "char", + "typeParameters": [ + "8" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "from", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "to", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "departure", + "type": "time", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "arrival", + "type": "time", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "airline_id", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "monday", + "type": "tinyint", + "typeParameters": [ + "1" + ], + "otherParameters": "DEFAULT '0'", + "comment": "" + }, + { + "name": "tuesday", + "type": "tinyint", + "typeParameters": [ + "1" + ], + "otherParameters": "DEFAULT '0'", + "comment": "" + }, + { + "name": "wednesday", + "type": "tinyint", + "typeParameters": [ + "1" + ], + "otherParameters": "DEFAULT '0'", + "comment": "" + }, + { + "name": "thursday", + "type": "tinyint", + "typeParameters": [ + "1" + ], + "otherParameters": "DEFAULT '0'", + "comment": "" + }, + { + "name": "friday", + "type": "tinyint", + "typeParameters": [ + "1" + ], + "otherParameters": "DEFAULT '0'", + "comment": "" + }, + { + "name": "saturday", + "type": "tinyint", + "typeParameters": [ + "1" + ], + "otherParameters": "DEFAULT '0'", + "comment": "" + }, + { + "name": "sunday", + "type": "tinyint", + "typeParameters": [ + "1" + ], + "otherParameters": "DEFAULT '0'", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "from" + ], + "otherParameters": "", + "name": "from_idx" + }, + { + "columns": [ + "to" + ], + "otherParameters": "", + "name": "to_idx" + }, + { + "columns": [ + "airline_id" + ], + "otherParameters": "", + "name": "airline_idx" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "flightno" + ], + "otherParameters": "" + } + }, + "passenger": { + "columns": [ + { + "name": "passenger_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "passportno", + "type": "char", + "typeParameters": [ + "9" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "firstname", + "type": "varchar", + "typeParameters": [ + "100" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "lastname", + "type": "varchar", + "typeParameters": [ + "100" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [], + "fulltext": [], + "unique": [ + { + "columns": [ + "passportno" + ], + "otherParameters": "", + "name": "pass_unq" + } + ] + }, + "primaryKey": { + "columns": [ + "passenger_id" + ], + "otherParameters": "" + } + }, + "passengerdetails": { + "columns": [ + { + "name": "passenger_id", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "birthdate", + "type": "date", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "sex", + "type": "char", + "typeParameters": [ + "1" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "street", + "type": "varchar", + "typeParameters": [ + "100" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "city", + "type": "varchar", + "typeParameters": [ + "100" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "zip", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "country", + "type": "varchar", + "typeParameters": [ + "100" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL", + "comment": "" + }, + { + "name": "emailaddress", + "type": "varchar", + "typeParameters": [ + "120" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + }, + { + "name": "telephoneno", + "type": "varchar", + "typeParameters": [ + "30" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "passenger_id" + ], + "otherParameters": "" + } + }, + "weatherdata": { + "columns": [ + { + "name": "log_date", + "type": "date", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "time", + "type": "time", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "station", + "type": "int", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "temp", + "type": "decimal", + "typeParameters": [ + "3", + "1" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "humidity", + "type": "decimal", + "typeParameters": [ + "4", + "1" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "airpressure", + "type": "decimal", + "typeParameters": [ + "10", + "2" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "wind", + "type": "decimal", + "typeParameters": [ + "5", + "2" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "winddirection", + "type": "smallint", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "weather", + "type": "enum", + "typeParameters": [ + "Nebel-Schneefall", + "Schneefall", + "Regen", + "Regen-Schneefall", + "Nebel-Regen", + "Nebel-Regen-Gewitter", + "Gewitter", + "Nebel", + "Regen-Gewitter" + ], + "otherParameters": "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "log_date", + "time", + "station" + ], + "otherParameters": "" + } + } + }, + "connections": [ + { + "type": "OneToMany", + "childTableName": "airline", + "childTableColumns": [ + "base_airport" + ], + "parentTableName": "airport", + "parentTableColumns": [ + "airport_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "airplane", + "childTableColumns": [ + "type_id" + ], + "parentTableName": "airplane_type", + "parentTableColumns": [ + "type_id" + ] + }, + { + "type": "OneToOne", + "childTableName": "airport_geo", + "childTableColumns": [ + "airport_id" + ], + "parentTableName": "airport", + "parentTableColumns": [ + "airport_id" + ] + }, + { + "type": "OneToOne", + "childTableName": "airport_reachable", + "childTableColumns": [ + "airport_id" + ], + "parentTableName": "airport", + "parentTableColumns": [ + "airport_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "booking", + "childTableColumns": [ + "flight_id" + ], + "parentTableName": "flight", + "parentTableColumns": [ + "flight_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "booking", + "childTableColumns": [ + "passenger_id" + ], + "parentTableName": "passenger", + "parentTableColumns": [ + "passenger_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "flight", + "childTableColumns": [ + "from" + ], + "parentTableName": "airport", + "parentTableColumns": [ + "airport_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "flight", + "childTableColumns": [ + "to" + ], + "parentTableName": "airport", + "parentTableColumns": [ + "airport_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "flight", + "childTableColumns": [ + "airline_id" + ], + "parentTableName": "airline", + "parentTableColumns": [ + "airline_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "flight", + "childTableColumns": [ + "airplane_id" + ], + "parentTableName": "airplane", + "parentTableColumns": [ + "airplane_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "flight", + "childTableColumns": [ + "flightno" + ], + "parentTableName": "flightschedule", + "parentTableColumns": [ + "flightno" + ] + }, + { + "type": "OneToMany", + "childTableName": "flight_log", + "childTableColumns": [ + "flight_id" + ], + "parentTableName": "flight", + "parentTableColumns": [ + "flight_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "flightschedule", + "childTableColumns": [ + "from" + ], + "parentTableName": "airport", + "parentTableColumns": [ + "airport_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "flightschedule", + "childTableColumns": [ + "to" + ], + "parentTableName": "airport", + "parentTableColumns": [ + "airport_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "flightschedule", + "childTableColumns": [ + "airline_id" + ], + "parentTableName": "airline", + "parentTableColumns": [ + "airline_id" + ] + }, + { + "type": "OneToOne", + "childTableName": "passengerdetails", + "childTableColumns": [ + "passenger_id" + ], + "parentTableName": "passenger", + "parentTableColumns": [ + "passenger_id" + ] + } + ] +} \ No newline at end of file diff --git a/example/output/airportdb/airportdb.md b/example/output/airportdb/airportdb.md index a2ef931..8ab7e90 100644 --- a/example/output/airportdb/airportdb.md +++ b/example/output/airportdb/airportdb.md @@ -1,8 +1,7 @@ -# Schema +## Tables +### `airline` table -## `airline` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -11,27 +10,26 @@ | airlinename | varchar ( 30 ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL | - | | base_airport | smallint | NOT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | airline_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | base_airport_idx | base_airport | - | -### Unique Indexes +#### Unique Indexes | Name | Columns | Parameters | | --- | --- | --- | | iata_unq | iata | - | +### `airplane` table -## `airplane` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -40,21 +38,20 @@ | type_id | int | NOT NULL | - | | airline_id | int | NOT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | airplane_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | type_id | type_id | - | +### `airplane_type` table -## `airplane_type` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -62,21 +59,20 @@ | identifier | varchar ( 50 ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL | - | | description | text | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | type_id | - | -### Fulltext Indexes +#### Fulltext Indexes | Name | Columns | Parameters | | --- | --- | --- | | description_full | identifier, description | - | +### `airport` table -## `airport` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -85,28 +81,27 @@ | icao | char ( 4 ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL | - | | name | varchar ( 50 ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | airport_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | name_idx | name | - | | iata_idx | iata | - | -### Unique Indexes +#### Unique Indexes | Name | Columns | Parameters | | --- | --- | --- | | icao_unq | icao | - | +### `airport_geo` table -## `airport_geo` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -118,36 +113,34 @@ | longitude | decimal ( 11, 8 ) | NOT NULL | - | | geolocation | point | NOT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | airport_id | - | -### Spatial Indexes +#### Spatial Indexes | Name | Columns | Parameters | | --- | --- | --- | | geolocation_spt | geolocation | - | +### `airport_reachable` table -## `airport_reachable` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | | airport_id | smallint | NOT NULL | - | | hops | int | DEFAULT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | airport_id | - | +### `booking` table -## `booking` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -157,28 +150,27 @@ | passenger_id | int | NOT NULL | - | | price | decimal ( 10, 2 ) | NOT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | booking_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | flight_idx | flight_id | - | | passenger_idx | passenger_id | - | -### Unique Indexes +#### Unique Indexes | Name | Columns | Parameters | | --- | --- | --- | | seatplan_unq | flight_id, seat | - | +### `employee` table -## `employee` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -198,21 +190,20 @@ | password | char ( 32 ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL | - | | department | enum ( Marketing, Buchhaltung, Management, Logistik, Flugfeld ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | employee_id | - | -### Unique Indexes +#### Unique Indexes | Name | Columns | Parameters | | --- | --- | --- | | user_unq | username | - | +### `flight` table -## `flight` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -225,13 +216,13 @@ | airline_id | smallint | NOT NULL | - | | airplane_id | int | NOT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | flight_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | @@ -242,10 +233,9 @@ | airline_idx | airline_id | - | | airplane_idx | airplane_id | - | | flightno | flightno | - | +### `flight_log` table -## `flight_log` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -269,21 +259,20 @@ | airline_id_new | smallint | NOT NULL | - | | comment | varchar ( 200 ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | flight_log_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | flight_log_ibfk_1 | flight_id | - | +### `flightschedule` table -## `flightschedule` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -301,23 +290,22 @@ | saturday | tinyint ( 1 ) | DEFAULT '0' | - | | sunday | tinyint ( 1 ) | DEFAULT '0' | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | flightno | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | from_idx | from | - | | to_idx | to | - | | airline_idx | airline_id | - | +### `passenger` table -## `passenger` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -326,21 +314,20 @@ | firstname | varchar ( 100 ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL | - | | lastname | varchar ( 100 ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | passenger_id | - | -### Unique Indexes +#### Unique Indexes | Name | Columns | Parameters | | --- | --- | --- | | pass_unq | passportno | - | +### `passengerdetails` table -## `passengerdetails` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -354,15 +341,14 @@ | emailaddress | varchar ( 120 ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL | - | | telephoneno | varchar ( 30 ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | passenger_id | - | +### `weatherdata` table -## `weatherdata` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -376,7 +362,7 @@ | winddirection | smallint | NOT NULL | - | | weather | enum ( Nebel-Schneefall, Schneefall, Regen, Regen-Schneefall, Nebel-Regen, Nebel-Regen-Gewitter, Gewitter, Nebel, Regen-Gewitter ) | CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | diff --git a/example/output/airportdb/airportdb.png b/example/output/airportdb/airportdb.png index da82598..80e7060 100644 Binary files a/example/output/airportdb/airportdb.png and b/example/output/airportdb/airportdb.png differ diff --git a/example/output/airportdb/airportdb.puml b/example/output/airportdb/airportdb.puml index 63f792a..9826220 100644 --- a/example/output/airportdb/airportdb.puml +++ b/example/output/airportdb/airportdb.puml @@ -1,21 +1,16 @@ @startuml -!ifndef TABLE_BORDER_COLOR -!define TABLE_BORDER_COLOR Chocolate -!endif - -!ifndef TABLE_BACKGROUND_COLOR -!define TABLE_BACKGROUND_COLOR AntiqueWhite -!endif +!$table_border_color ?= "Chocolate" +!$table_background_color ?= "AntiqueWhite" skinparam class { - BackgroundColor TABLE_BACKGROUND_COLOR - BorderColor TABLE_BORDER_COLOR - ArrowColor TABLE_BORDER_COLOR + BackgroundColor $table_background_color + BorderColor $table_border_color + ArrowColor $table_border_color } !procedure $table($name) -class "$name" << (T, TABLE_BORDER_COLOR ) >> +class "$name" <> << (T, $table_border_color ) >> !endprocedure !function $key_columns($columns, $otherParameters="") @@ -69,16 +64,14 @@ class "$name" << (T, TABLE_BORDER_COLOR ) >> !endprocedure !procedure $connection_one_to_one($from, $to) -$from "1" -- "1" $to + $from "1" -- "1" $to !endprocedure !procedure $connection_one_to_many($from, $to) -$from "n" }-- "1" $to + $from "n" }-- "1" $to !endprocedure hide methods -hide stereotypes - skinparam linetype polyline left to right direction diff --git a/example/output/airportdb/airportdb.svg b/example/output/airportdb/airportdb.svg index f54871d..47460bb 100644 --- a/example/output/airportdb/airportdb.svg +++ b/example/output/airportdb/airportdb.svg @@ -1 +1 @@ -airlineairline_id smallintNOT NULL AUTO_INCREMENTiata char[2]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLairlinename varchar[30]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLbase_airport smallintNOT NULLPK[airline_id]KEY[base_airport]UNIQUE KEY[iata]airplaneairplane_id intNOT NULL AUTO_INCREMENTcapacity mediumintunsigned NOT NULLtype_id intNOT NULLairline_id intNOT NULLPK[airplane_id]KEY[type_id]airplane_typetype_id intNOT NULL AUTO_INCREMENTidentifier varchar[50]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLdescription textCHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ciPK[type_id]FULLTEXT KEY[identifier, description]airportairport_id smallintNOT NULL AUTO_INCREMENTiata char[3]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLicao char[4]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLname varchar[50]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLPK[airport_id]KEY[name]KEY[iata]UNIQUE KEY[icao]airport_geoairport_id smallintNOT NULLname varchar[50]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLcity varchar[50]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLcountry varchar[50]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLlatitude decimal[11, 8]NOT NULLlongitude decimal[11, 8]NOT NULLgeolocation pointNOT NULLPK[airport_id]SPATIAL KEY[geolocation]airport_reachableairport_id smallintNOT NULLhops intDEFAULT NULLPK[airport_id]bookingbooking_id intNOT NULL AUTO_INCREMENTflight_id intNOT NULLseat char[4]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLpassenger_id intNOT NULLprice decimal[10, 2]NOT NULLPK[booking_id]KEY[flight_id]KEY[passenger_id]UNIQUE KEY[flight_id, seat]employeeemployee_id intNOT NULL AUTO_INCREMENTfirstname varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLlastname varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLbirthdate dateNOT NULLsex char[1]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLstreet varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLcity varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLzip smallintNOT NULLcountry varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLemailaddress varchar[120]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLtelephoneno varchar[30]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLsalary decimal[8, 2]DEFAULT NULLusername varchar[20]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLpassword char[32]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLdepartment enum[Marketing, Buchhaltung, Management, Logistik, Flugfeld]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLPK[employee_id]UNIQUE KEY[username]flightflight_id intNOT NULL AUTO_INCREMENTflightno char[8]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLfrom smallintNOT NULLto smallintNOT NULLdeparture datetimeNOT NULLarrival datetimeNOT NULLairline_id smallintNOT NULLairplane_id intNOT NULLPK[flight_id]KEY[from]KEY[to]KEY[departure]KEY[arrival]KEY[airline_id]KEY[airplane_id]KEY[flightno]flight_logflight_log_id intunsigned NOT NULL AUTO_INCREMENTlog_date datetimeNOT NULLuser varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLflight_id intNOT NULLflightno_old char[8]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLflightno_new char[8]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLfrom_old smallintNOT NULLto_old smallintNOT NULLfrom_new smallintNOT NULLto_new smallintNOT NULLdeparture_old datetimeNOT NULLarrival_old datetimeNOT NULLdeparture_new datetimeNOT NULLarrival_new datetimeNOT NULLairplane_id_old intNOT NULLairplane_id_new intNOT NULLairline_id_old smallintNOT NULLairline_id_new smallintNOT NULLcomment varchar[200]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLPK[flight_log_id]KEY[flight_id]flightscheduleflightno char[8]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLfrom smallintNOT NULLto smallintNOT NULLdeparture timeNOT NULLarrival timeNOT NULLairline_id smallintNOT NULLmonday tinyint[1]DEFAULT "0"tuesday tinyint[1]DEFAULT "0"wednesday tinyint[1]DEFAULT "0"thursday tinyint[1]DEFAULT "0"friday tinyint[1]DEFAULT "0"saturday tinyint[1]DEFAULT "0"sunday tinyint[1]DEFAULT "0"PK[flightno]KEY[from]KEY[to]KEY[airline_id]passengerpassenger_id intNOT NULL AUTO_INCREMENTpassportno char[9]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLfirstname varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLlastname varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLPK[passenger_id]UNIQUE KEY[passportno]passengerdetailspassenger_id intNOT NULLbirthdate dateNOT NULLsex char[1]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLstreet varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLcity varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLzip smallintNOT NULLcountry varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLemailaddress varchar[120]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLtelephoneno varchar[30]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLPK[passenger_id]weatherdatalog_date dateNOT NULLtime timeNOT NULLstation intNOT NULLtemp decimal[3, 1]NOT NULLhumidity decimal[4, 1]NOT NULLairpressure decimal[10, 2]NOT NULLwind decimal[5, 2]NOT NULLwinddirection smallintNOT NULLweather enum[Nebel-Schneefall, Schneefall, Regen, Regen-Schneefall, Nebel-Regen, Nebel-Regen-Gewitter, Gewitter, Nebel, Regen-Gewitter]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLPK[log_date, time, station]n1n11111n1n1n1n1n1n1n1n1n1n1n111 \ No newline at end of file +«table»airlineairline_id smallintNOT NULL AUTO_INCREMENTiata char[2]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLairlinename varchar[30]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLbase_airport smallintNOT NULLPK[airline_id]KEY[base_airport]UNIQUE KEY[iata]«table»airplaneairplane_id intNOT NULL AUTO_INCREMENTcapacity mediumintunsigned NOT NULLtype_id intNOT NULLairline_id intNOT NULLPK[airplane_id]KEY[type_id]«table»airplane_typetype_id intNOT NULL AUTO_INCREMENTidentifier varchar[50]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLdescription textCHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ciPK[type_id]FULLTEXT KEY[identifier, description]«table»airportairport_id smallintNOT NULL AUTO_INCREMENTiata char[3]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLicao char[4]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLname varchar[50]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLPK[airport_id]KEY[name]KEY[iata]UNIQUE KEY[icao]«table»airport_geoairport_id smallintNOT NULLname varchar[50]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLcity varchar[50]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLcountry varchar[50]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLlatitude decimal[11, 8]NOT NULLlongitude decimal[11, 8]NOT NULLgeolocation pointNOT NULLPK[airport_id]SPATIAL KEY[geolocation]«table»airport_reachableairport_id smallintNOT NULLhops intDEFAULT NULLPK[airport_id]«table»bookingbooking_id intNOT NULL AUTO_INCREMENTflight_id intNOT NULLseat char[4]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLpassenger_id intNOT NULLprice decimal[10, 2]NOT NULLPK[booking_id]KEY[flight_id]KEY[passenger_id]UNIQUE KEY[flight_id, seat]«table»employeeemployee_id intNOT NULL AUTO_INCREMENTfirstname varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLlastname varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLbirthdate dateNOT NULLsex char[1]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLstreet varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLcity varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLzip smallintNOT NULLcountry varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLemailaddress varchar[120]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLtelephoneno varchar[30]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLsalary decimal[8, 2]DEFAULT NULLusername varchar[20]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLpassword char[32]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLdepartment enum[Marketing, Buchhaltung, Management, Logistik, Flugfeld]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLPK[employee_id]UNIQUE KEY[username]«table»flightflight_id intNOT NULL AUTO_INCREMENTflightno char[8]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLfrom smallintNOT NULLto smallintNOT NULLdeparture datetimeNOT NULLarrival datetimeNOT NULLairline_id smallintNOT NULLairplane_id intNOT NULLPK[flight_id]KEY[from]KEY[to]KEY[departure]KEY[arrival]KEY[airline_id]KEY[airplane_id]KEY[flightno]«table»flight_logflight_log_id intunsigned NOT NULL AUTO_INCREMENTlog_date datetimeNOT NULLuser varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLflight_id intNOT NULLflightno_old char[8]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLflightno_new char[8]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLfrom_old smallintNOT NULLto_old smallintNOT NULLfrom_new smallintNOT NULLto_new smallintNOT NULLdeparture_old datetimeNOT NULLarrival_old datetimeNOT NULLdeparture_new datetimeNOT NULLarrival_new datetimeNOT NULLairplane_id_old intNOT NULLairplane_id_new intNOT NULLairline_id_old smallintNOT NULLairline_id_new smallintNOT NULLcomment varchar[200]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLPK[flight_log_id]KEY[flight_id]«table»flightscheduleflightno char[8]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLfrom smallintNOT NULLto smallintNOT NULLdeparture timeNOT NULLarrival timeNOT NULLairline_id smallintNOT NULLmonday tinyint[1]DEFAULT "0"tuesday tinyint[1]DEFAULT "0"wednesday tinyint[1]DEFAULT "0"thursday tinyint[1]DEFAULT "0"friday tinyint[1]DEFAULT "0"saturday tinyint[1]DEFAULT "0"sunday tinyint[1]DEFAULT "0"PK[flightno]KEY[from]KEY[to]KEY[airline_id]«table»passengerpassenger_id intNOT NULL AUTO_INCREMENTpassportno char[9]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLfirstname varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLlastname varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLPK[passenger_id]UNIQUE KEY[passportno]«table»passengerdetailspassenger_id intNOT NULLbirthdate dateNOT NULLsex char[1]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLstreet varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLcity varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLzip smallintNOT NULLcountry varchar[100]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULLemailaddress varchar[120]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLtelephoneno varchar[30]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLPK[passenger_id]«table»weatherdatalog_date dateNOT NULLtime timeNOT NULLstation intNOT NULLtemp decimal[3, 1]NOT NULLhumidity decimal[4, 1]NOT NULLairpressure decimal[10, 2]NOT NULLwind decimal[5, 2]NOT NULLwinddirection smallintNOT NULLweather enum[Nebel-Schneefall, Schneefall, Regen, Regen-Schneefall, Nebel-Regen, Nebel-Regen-Gewitter, Gewitter, Nebel, Regen-Gewitter]CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULLPK[log_date, time, station]n1n11111n1n1n1n1n1n1n1n1n1n1n111 \ No newline at end of file diff --git a/example/output/sakila/sakila.json b/example/output/sakila/sakila.json new file mode 100644 index 0000000..69bd327 --- /dev/null +++ b/example/output/sakila/sakila.json @@ -0,0 +1,1370 @@ +{ + "tables": { + "actor": { + "columns": [ + { + "name": "actor_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "first_name", + "type": "VARCHAR", + "typeParameters": [ + "45" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "last_name", + "type": "VARCHAR", + "typeParameters": [ + "45" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "last_name" + ], + "otherParameters": "", + "name": "idx_actor_last_name" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "actor_id" + ], + "otherParameters": "" + } + }, + "address": { + "columns": [ + { + "name": "address_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "address", + "type": "VARCHAR", + "typeParameters": [ + "50" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "address2", + "type": "VARCHAR", + "typeParameters": [ + "50" + ], + "otherParameters": "DEFAULT NULL", + "comment": "" + }, + { + "name": "district", + "type": "VARCHAR", + "typeParameters": [ + "20" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "city_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "postal_code", + "type": "VARCHAR", + "typeParameters": [ + "10" + ], + "otherParameters": "DEFAULT NULL", + "comment": "" + }, + { + "name": "phone", + "type": "VARCHAR", + "typeParameters": [ + "20" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "city_id" + ], + "otherParameters": "", + "name": "idx_fk_city_id" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "address_id" + ], + "otherParameters": "" + } + }, + "category": { + "columns": [ + { + "name": "category_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "name", + "type": "VARCHAR", + "typeParameters": [ + "25" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "category_id" + ], + "otherParameters": "" + } + }, + "city": { + "columns": [ + { + "name": "city_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "city", + "type": "VARCHAR", + "typeParameters": [ + "50" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "country_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "country_id" + ], + "otherParameters": "", + "name": "idx_fk_country_id" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "city_id" + ], + "otherParameters": "" + } + }, + "country": { + "columns": [ + { + "name": "country_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "country", + "type": "VARCHAR", + "typeParameters": [ + "50" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "country_id" + ], + "otherParameters": "" + } + }, + "customer": { + "columns": [ + { + "name": "customer_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "store_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "first_name", + "type": "VARCHAR", + "typeParameters": [ + "45" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "last_name", + "type": "VARCHAR", + "typeParameters": [ + "45" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "email", + "type": "VARCHAR", + "typeParameters": [ + "50" + ], + "otherParameters": "DEFAULT NULL", + "comment": "" + }, + { + "name": "address_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "active", + "type": "BOOLEAN", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT TRUE", + "comment": "" + }, + { + "name": "create_date", + "type": "DATETIME", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "store_id" + ], + "otherParameters": "", + "name": "idx_fk_store_id" + }, + { + "columns": [ + "address_id" + ], + "otherParameters": "", + "name": "idx_fk_address_id" + }, + { + "columns": [ + "last_name" + ], + "otherParameters": "", + "name": "idx_last_name" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "customer_id" + ], + "otherParameters": "" + } + }, + "film": { + "columns": [ + { + "name": "film_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "title", + "type": "VARCHAR", + "typeParameters": [ + "255" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "description", + "type": "TEXT", + "typeParameters": [], + "otherParameters": "DEFAULT NULL", + "comment": "" + }, + { + "name": "release_year", + "type": "YEAR", + "typeParameters": [], + "otherParameters": "DEFAULT NULL", + "comment": "" + }, + { + "name": "language_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "original_language_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED DEFAULT NULL", + "comment": "" + }, + { + "name": "rental_duration", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL DEFAULT 3", + "comment": "" + }, + { + "name": "rental_rate", + "type": "DECIMAL", + "typeParameters": [ + "4", + "2" + ], + "otherParameters": "NOT NULL DEFAULT 4.99", + "comment": "" + }, + { + "name": "length", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED DEFAULT NULL", + "comment": "" + }, + { + "name": "replacement_cost", + "type": "DECIMAL", + "typeParameters": [ + "5", + "2" + ], + "otherParameters": "NOT NULL DEFAULT 19.99", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + }, + { + "name": "rating", + "type": "ENUM", + "typeParameters": [ + "G", + "PG", + "PG-13", + "R", + "NC-17" + ], + "otherParameters": "DEFAULT 'G'", + "comment": "" + }, + { + "name": "special_features", + "type": "SET", + "typeParameters": [ + "Trailers", + "Commentaries", + "Deleted Scenes", + "Behind the Scenes" + ], + "otherParameters": "DEFAULT NULL", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "title" + ], + "otherParameters": "", + "name": "idx_title" + }, + { + "columns": [ + "language_id" + ], + "otherParameters": "", + "name": "idx_fk_language_id" + }, + { + "columns": [ + "original_language_id" + ], + "otherParameters": "", + "name": "idx_fk_original_language_id" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "film_id" + ], + "otherParameters": "" + } + }, + "film_actor": { + "columns": [ + { + "name": "actor_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "film_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "film_id" + ], + "otherParameters": "", + "name": "idx_fk_film_id" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "actor_id", + "film_id" + ], + "otherParameters": "" + } + }, + "film_category": { + "columns": [ + { + "name": "film_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "category_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "film_id", + "category_id" + ], + "otherParameters": "" + } + }, + "film_text": { + "columns": [ + { + "name": "film_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "title", + "type": "VARCHAR", + "typeParameters": [ + "255" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "description", + "type": "TEXT", + "typeParameters": [], + "otherParameters": "", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [], + "fulltext": [ + { + "columns": [ + "title", + "description" + ], + "otherParameters": "", + "name": "idx_title_description" + } + ], + "unique": [] + }, + "primaryKey": { + "columns": [ + "film_id" + ], + "otherParameters": "" + } + }, + "inventory": { + "columns": [ + { + "name": "inventory_id", + "type": "MEDIUMINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "film_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "store_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "film_id" + ], + "otherParameters": "", + "name": "idx_fk_film_id" + }, + { + "columns": [ + "store_id", + "film_id" + ], + "otherParameters": "", + "name": "idx_store_id_film_id" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "inventory_id" + ], + "otherParameters": "" + } + }, + "language": { + "columns": [ + { + "name": "language_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "name", + "type": "CHAR", + "typeParameters": [ + "20" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "language_id" + ], + "otherParameters": "" + } + }, + "payment": { + "columns": [ + { + "name": "payment_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "customer_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "staff_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "rental_id", + "type": "INT", + "typeParameters": [], + "otherParameters": "DEFAULT NULL", + "comment": "" + }, + { + "name": "amount", + "type": "DECIMAL", + "typeParameters": [ + "5", + "2" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "payment_date", + "type": "DATETIME", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "staff_id" + ], + "otherParameters": "", + "name": "idx_fk_staff_id" + }, + { + "columns": [ + "customer_id" + ], + "otherParameters": "", + "name": "idx_fk_customer_id" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "payment_id" + ], + "otherParameters": "" + } + }, + "rental": { + "columns": [ + { + "name": "rental_id", + "type": "INT", + "typeParameters": [], + "otherParameters": "NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "rental_date", + "type": "DATETIME", + "typeParameters": [], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "inventory_id", + "type": "MEDIUMINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "customer_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "return_date", + "type": "DATETIME", + "typeParameters": [], + "otherParameters": "DEFAULT NULL", + "comment": "" + }, + { + "name": "staff_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "inventory_id" + ], + "otherParameters": "", + "name": "idx_fk_inventory_id" + }, + { + "columns": [ + "customer_id" + ], + "otherParameters": "", + "name": "idx_fk_customer_id" + }, + { + "columns": [ + "staff_id" + ], + "otherParameters": "", + "name": "idx_fk_staff_id" + } + ], + "spatial": [], + "fulltext": [], + "unique": [ + { + "columns": [ + "rental_date", + "inventory_id", + "customer_id" + ], + "otherParameters": "", + "name": "" + } + ] + }, + "primaryKey": { + "columns": [ + "rental_id" + ], + "otherParameters": "" + } + }, + "staff": { + "columns": [ + { + "name": "staff_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "first_name", + "type": "VARCHAR", + "typeParameters": [ + "45" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "last_name", + "type": "VARCHAR", + "typeParameters": [ + "45" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "address_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "picture", + "type": "BLOB", + "typeParameters": [], + "otherParameters": "DEFAULT NULL", + "comment": "" + }, + { + "name": "email", + "type": "VARCHAR", + "typeParameters": [ + "50" + ], + "otherParameters": "DEFAULT NULL", + "comment": "" + }, + { + "name": "store_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "active", + "type": "BOOLEAN", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT TRUE", + "comment": "" + }, + { + "name": "username", + "type": "VARCHAR", + "typeParameters": [ + "16" + ], + "otherParameters": "NOT NULL", + "comment": "" + }, + { + "name": "password", + "type": "VARCHAR", + "typeParameters": [ + "40" + ], + "otherParameters": "BINARY DEFAULT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "store_id" + ], + "otherParameters": "", + "name": "idx_fk_store_id" + }, + { + "columns": [ + "address_id" + ], + "otherParameters": "", + "name": "idx_fk_address_id" + } + ], + "spatial": [], + "fulltext": [], + "unique": [] + }, + "primaryKey": { + "columns": [ + "staff_id" + ], + "otherParameters": "" + } + }, + "store": { + "columns": [ + { + "name": "store_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL AUTO_INCREMENT", + "comment": "" + }, + { + "name": "manager_staff_id", + "type": "TINYINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "address_id", + "type": "SMALLINT", + "typeParameters": [], + "otherParameters": "UNSIGNED NOT NULL", + "comment": "" + }, + { + "name": "last_update", + "type": "TIMESTAMP", + "typeParameters": [], + "otherParameters": "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "comment": "" + } + ], + "indexes": { + "simple": [ + { + "columns": [ + "address_id" + ], + "otherParameters": "", + "name": "idx_fk_address_id" + } + ], + "spatial": [], + "fulltext": [], + "unique": [ + { + "columns": [ + "manager_staff_id" + ], + "otherParameters": "", + "name": "idx_unique_manager" + } + ] + }, + "primaryKey": { + "columns": [ + "store_id" + ], + "otherParameters": "" + } + } + }, + "connections": [ + { + "type": "OneToMany", + "childTableName": "address", + "childTableColumns": [ + "city_id" + ], + "parentTableName": "city", + "parentTableColumns": [ + "city_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "city", + "childTableColumns": [ + "country_id" + ], + "parentTableName": "country", + "parentTableColumns": [ + "country_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "customer", + "childTableColumns": [ + "address_id" + ], + "parentTableName": "address", + "parentTableColumns": [ + "address_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "customer", + "childTableColumns": [ + "store_id" + ], + "parentTableName": "store", + "parentTableColumns": [ + "store_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "film", + "childTableColumns": [ + "language_id" + ], + "parentTableName": "language", + "parentTableColumns": [ + "language_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "film", + "childTableColumns": [ + "original_language_id" + ], + "parentTableName": "language", + "parentTableColumns": [ + "language_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "film_actor", + "childTableColumns": [ + "actor_id" + ], + "parentTableName": "actor", + "parentTableColumns": [ + "actor_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "film_actor", + "childTableColumns": [ + "film_id" + ], + "parentTableName": "film", + "parentTableColumns": [ + "film_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "film_category", + "childTableColumns": [ + "film_id" + ], + "parentTableName": "film", + "parentTableColumns": [ + "film_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "film_category", + "childTableColumns": [ + "category_id" + ], + "parentTableName": "category", + "parentTableColumns": [ + "category_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "inventory", + "childTableColumns": [ + "store_id" + ], + "parentTableName": "store", + "parentTableColumns": [ + "store_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "inventory", + "childTableColumns": [ + "film_id" + ], + "parentTableName": "film", + "parentTableColumns": [ + "film_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "payment", + "childTableColumns": [ + "rental_id" + ], + "parentTableName": "rental", + "parentTableColumns": [ + "rental_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "payment", + "childTableColumns": [ + "customer_id" + ], + "parentTableName": "customer", + "parentTableColumns": [ + "customer_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "payment", + "childTableColumns": [ + "staff_id" + ], + "parentTableName": "staff", + "parentTableColumns": [ + "staff_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "rental", + "childTableColumns": [ + "staff_id" + ], + "parentTableName": "staff", + "parentTableColumns": [ + "staff_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "rental", + "childTableColumns": [ + "inventory_id" + ], + "parentTableName": "inventory", + "parentTableColumns": [ + "inventory_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "rental", + "childTableColumns": [ + "customer_id" + ], + "parentTableName": "customer", + "parentTableColumns": [ + "customer_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "staff", + "childTableColumns": [ + "store_id" + ], + "parentTableName": "store", + "parentTableColumns": [ + "store_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "staff", + "childTableColumns": [ + "address_id" + ], + "parentTableName": "address", + "parentTableColumns": [ + "address_id" + ] + }, + { + "type": "OneToOne", + "childTableName": "store", + "childTableColumns": [ + "manager_staff_id" + ], + "parentTableName": "staff", + "parentTableColumns": [ + "staff_id" + ] + }, + { + "type": "OneToMany", + "childTableName": "store", + "childTableColumns": [ + "address_id" + ], + "parentTableName": "address", + "parentTableColumns": [ + "address_id" + ] + } + ] +} \ No newline at end of file diff --git a/example/output/sakila/sakila.md b/example/output/sakila/sakila.md index 1fa6607..40d0e46 100644 --- a/example/output/sakila/sakila.md +++ b/example/output/sakila/sakila.md @@ -1,8 +1,7 @@ -# Schema +## Tables +### `actor` table -## `actor` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -11,21 +10,20 @@ | last_name | VARCHAR ( 45 ) | NOT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | actor_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_actor_last_name | last_name | - | +### `address` table -## `address` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -38,21 +36,20 @@ | phone | VARCHAR ( 20 ) | NOT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | address_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_fk_city_id | city_id | - | +### `category` table -## `category` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -60,15 +57,14 @@ | name | VARCHAR ( 25 ) | NOT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | category_id | - | +### `city` table -## `city` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -77,21 +73,20 @@ | country_id | SMALLINT | UNSIGNED NOT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | city_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_fk_country_id | country_id | - | +### `country` table -## `country` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -99,15 +94,14 @@ | country | VARCHAR ( 50 ) | NOT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | country_id | - | +### `customer` table -## `customer` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -121,23 +115,22 @@ | create_date | DATETIME | NOT NULL | - | | last_update | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | customer_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_fk_store_id | store_id | - | | idx_fk_address_id | address_id | - | | idx_last_name | last_name | - | +### `film` table -## `film` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -155,23 +148,22 @@ | rating | ENUM ( G, PG, PG-13, R, NC-17 ) | DEFAULT 'G' | - | | special_features | SET ( Trailers, Commentaries, Deleted Scenes, Behind the Scenes ) | DEFAULT NULL | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | film_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_title | title | - | | idx_fk_language_id | language_id | - | | idx_fk_original_language_id | original_language_id | - | +### `film_actor` table -## `film_actor` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -179,21 +171,20 @@ | film_id | SMALLINT | UNSIGNED NOT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | actor_id, film_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_fk_film_id | film_id | - | +### `film_category` table -## `film_category` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -201,15 +192,14 @@ | category_id | TINYINT | UNSIGNED NOT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | film_id, category_id | - | +### `film_text` table -## `film_text` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -217,21 +207,20 @@ | title | VARCHAR ( 255 ) | NOT NULL | - | | description | TEXT | - | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | film_id | - | -### Fulltext Indexes +#### Fulltext Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_title_description | title, description | - | +### `inventory` table -## `inventory` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -240,22 +229,21 @@ | store_id | TINYINT | UNSIGNED NOT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | inventory_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_fk_film_id | film_id | - | | idx_store_id_film_id | store_id, film_id | - | +### `language` table -## `language` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -263,15 +251,14 @@ | name | CHAR ( 20 ) | NOT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | language_id | - | +### `payment` table -## `payment` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -283,22 +270,21 @@ | payment_date | DATETIME | NOT NULL | - | | last_update | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | payment_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_fk_staff_id | staff_id | - | | idx_fk_customer_id | customer_id | - | +### `rental` table -## `rental` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -310,13 +296,13 @@ | staff_id | TINYINT | UNSIGNED NOT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | rental_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | @@ -324,15 +310,14 @@ | idx_fk_customer_id | customer_id | - | | idx_fk_staff_id | staff_id | - | -### Unique Indexes +#### Unique Indexes | Name | Columns | Parameters | | --- | --- | --- | | | rental_date, inventory_id, customer_id | - | +### `staff` table -## `staff` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -348,22 +333,21 @@ | password | VARCHAR ( 40 ) | BINARY DEFAULT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | staff_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_fk_store_id | store_id | - | | idx_fk_address_id | address_id | - | +### `store` table -## `store` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -372,19 +356,19 @@ | address_id | SMALLINT | UNSIGNED NOT NULL | - | | last_update | TIMESTAMP | NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | - | -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | | store_id | - | -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_fk_address_id | address_id | - | -### Unique Indexes +#### Unique Indexes | Name | Columns | Parameters | | --- | --- | --- | diff --git a/example/output/sakila/sakila.png b/example/output/sakila/sakila.png index 33f482b..a07b317 100644 Binary files a/example/output/sakila/sakila.png and b/example/output/sakila/sakila.png differ diff --git a/example/output/sakila/sakila.puml b/example/output/sakila/sakila.puml index 6b7e957..12a6403 100644 --- a/example/output/sakila/sakila.puml +++ b/example/output/sakila/sakila.puml @@ -1,21 +1,16 @@ @startuml -!ifndef TABLE_BORDER_COLOR -!define TABLE_BORDER_COLOR Chocolate -!endif - -!ifndef TABLE_BACKGROUND_COLOR -!define TABLE_BACKGROUND_COLOR AntiqueWhite -!endif +!$table_border_color ?= "Chocolate" +!$table_background_color ?= "AntiqueWhite" skinparam class { - BackgroundColor TABLE_BACKGROUND_COLOR - BorderColor TABLE_BORDER_COLOR - ArrowColor TABLE_BORDER_COLOR + BackgroundColor $table_background_color + BorderColor $table_border_color + ArrowColor $table_border_color } !procedure $table($name) -class "$name" << (T, TABLE_BORDER_COLOR ) >> +class "$name" <
> << (T, $table_border_color ) >> !endprocedure !function $key_columns($columns, $otherParameters="") @@ -69,16 +64,14 @@ class "$name" << (T, TABLE_BORDER_COLOR ) >> !endprocedure !procedure $connection_one_to_one($from, $to) -$from "1" -- "1" $to + $from "1" -- "1" $to !endprocedure !procedure $connection_one_to_many($from, $to) -$from "n" }-- "1" $to + $from "n" }-- "1" $to !endprocedure hide methods -hide stereotypes - skinparam linetype polyline left to right direction diff --git a/example/output/sakila/sakila.svg b/example/output/sakila/sakila.svg index f7c30bd..5eeeab5 100644 --- a/example/output/sakila/sakila.svg +++ b/example/output/sakila/sakila.svg @@ -1 +1 @@ -actoractor_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTfirst_name VARCHAR[45]NOT NULLlast_name VARCHAR[45]NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[actor_id]KEY[last_name]addressaddress_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTaddress VARCHAR[50]NOT NULLaddress2 VARCHAR[50]DEFAULT NULLdistrict VARCHAR[20]NOT NULLcity_id SMALLINTUNSIGNED NOT NULLpostal_code VARCHAR[10]DEFAULT NULLphone VARCHAR[20]NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[address_id]KEY[city_id]categorycategory_id TINYINTUNSIGNED NOT NULL AUTO_INCREMENTname VARCHAR[25]NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[category_id]citycity_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTcity VARCHAR[50]NOT NULLcountry_id SMALLINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[city_id]KEY[country_id]countrycountry_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTcountry VARCHAR[50]NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[country_id]customercustomer_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTstore_id TINYINTUNSIGNED NOT NULLfirst_name VARCHAR[45]NOT NULLlast_name VARCHAR[45]NOT NULLemail VARCHAR[50]DEFAULT NULLaddress_id SMALLINTUNSIGNED NOT NULLactive BOOLEANNOT NULL DEFAULT TRUEcreate_date DATETIMENOT NULLlast_update TIMESTAMPDEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[customer_id]KEY[store_id]KEY[address_id]KEY[last_name]filmfilm_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTtitle VARCHAR[255]NOT NULLdescription TEXTDEFAULT NULLrelease_year YEARDEFAULT NULLlanguage_id TINYINTUNSIGNED NOT NULLoriginal_language_id TINYINTUNSIGNED DEFAULT NULLrental_duration TINYINTUNSIGNED NOT NULL DEFAULT 3rental_rate DECIMAL[4, 2]NOT NULL DEFAULT 4.99length SMALLINTUNSIGNED DEFAULT NULLreplacement_cost DECIMAL[5, 2]NOT NULL DEFAULT 19.99last_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPrating ENUM[G, PG, PG-13, R, NC-17]DEFAULT "G"special_features SET[Trailers, Commentaries, Deleted Scenes, Behind the Scenes]DEFAULT NULLPK[film_id]KEY[title]KEY[language_id]KEY[original_language_id]film_actoractor_id SMALLINTUNSIGNED NOT NULLfilm_id SMALLINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[actor_id, film_id]KEY[film_id]film_categoryfilm_id SMALLINTUNSIGNED NOT NULLcategory_id TINYINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[film_id, category_id]film_textfilm_id SMALLINTNOT NULLtitle VARCHAR[255]NOT NULLdescription TEXTPK[film_id]FULLTEXT KEY[title, description]inventoryinventory_id MEDIUMINTUNSIGNED NOT NULL AUTO_INCREMENTfilm_id SMALLINTUNSIGNED NOT NULLstore_id TINYINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[inventory_id]KEY[film_id]KEY[store_id, film_id]languagelanguage_id TINYINTUNSIGNED NOT NULL AUTO_INCREMENTname CHAR[20]NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[language_id]paymentpayment_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTcustomer_id SMALLINTUNSIGNED NOT NULLstaff_id TINYINTUNSIGNED NOT NULLrental_id INTDEFAULT NULLamount DECIMAL[5, 2]NOT NULLpayment_date DATETIMENOT NULLlast_update TIMESTAMPDEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[payment_id]KEY[staff_id]KEY[customer_id]rentalrental_id INTNOT NULL AUTO_INCREMENTrental_date DATETIMENOT NULLinventory_id MEDIUMINTUNSIGNED NOT NULLcustomer_id SMALLINTUNSIGNED NOT NULLreturn_date DATETIMEDEFAULT NULLstaff_id TINYINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[rental_id]KEY[inventory_id]KEY[customer_id]KEY[staff_id]UNIQUE KEY[rental_date, inventory_id, customer_id]staffstaff_id TINYINTUNSIGNED NOT NULL AUTO_INCREMENTfirst_name VARCHAR[45]NOT NULLlast_name VARCHAR[45]NOT NULLaddress_id SMALLINTUNSIGNED NOT NULLpicture BLOBDEFAULT NULLemail VARCHAR[50]DEFAULT NULLstore_id TINYINTUNSIGNED NOT NULLactive BOOLEANNOT NULL DEFAULT TRUEusername VARCHAR[16]NOT NULLpassword VARCHAR[40]BINARY DEFAULT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[staff_id]KEY[store_id]KEY[address_id]storestore_id TINYINTUNSIGNED NOT NULL AUTO_INCREMENTmanager_staff_id TINYINTUNSIGNED NOT NULLaddress_id SMALLINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[store_id]KEY[address_id]UNIQUE KEY[manager_staff_id]n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n111n1n1 \ No newline at end of file +«table»actoractor_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTfirst_name VARCHAR[45]NOT NULLlast_name VARCHAR[45]NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[actor_id]KEY[last_name]«table»addressaddress_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTaddress VARCHAR[50]NOT NULLaddress2 VARCHAR[50]DEFAULT NULLdistrict VARCHAR[20]NOT NULLcity_id SMALLINTUNSIGNED NOT NULLpostal_code VARCHAR[10]DEFAULT NULLphone VARCHAR[20]NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[address_id]KEY[city_id]«table»categorycategory_id TINYINTUNSIGNED NOT NULL AUTO_INCREMENTname VARCHAR[25]NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[category_id]«table»citycity_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTcity VARCHAR[50]NOT NULLcountry_id SMALLINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[city_id]KEY[country_id]«table»countrycountry_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTcountry VARCHAR[50]NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[country_id]«table»customercustomer_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTstore_id TINYINTUNSIGNED NOT NULLfirst_name VARCHAR[45]NOT NULLlast_name VARCHAR[45]NOT NULLemail VARCHAR[50]DEFAULT NULLaddress_id SMALLINTUNSIGNED NOT NULLactive BOOLEANNOT NULL DEFAULT TRUEcreate_date DATETIMENOT NULLlast_update TIMESTAMPDEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[customer_id]KEY[store_id]KEY[address_id]KEY[last_name]«table»filmfilm_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTtitle VARCHAR[255]NOT NULLdescription TEXTDEFAULT NULLrelease_year YEARDEFAULT NULLlanguage_id TINYINTUNSIGNED NOT NULLoriginal_language_id TINYINTUNSIGNED DEFAULT NULLrental_duration TINYINTUNSIGNED NOT NULL DEFAULT 3rental_rate DECIMAL[4, 2]NOT NULL DEFAULT 4.99length SMALLINTUNSIGNED DEFAULT NULLreplacement_cost DECIMAL[5, 2]NOT NULL DEFAULT 19.99last_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPrating ENUM[G, PG, PG-13, R, NC-17]DEFAULT "G"special_features SET[Trailers, Commentaries, Deleted Scenes, Behind the Scenes]DEFAULT NULLPK[film_id]KEY[title]KEY[language_id]KEY[original_language_id]«table»film_actoractor_id SMALLINTUNSIGNED NOT NULLfilm_id SMALLINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[actor_id, film_id]KEY[film_id]«table»film_categoryfilm_id SMALLINTUNSIGNED NOT NULLcategory_id TINYINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[film_id, category_id]«table»film_textfilm_id SMALLINTNOT NULLtitle VARCHAR[255]NOT NULLdescription TEXTPK[film_id]FULLTEXT KEY[title, description]«table»inventoryinventory_id MEDIUMINTUNSIGNED NOT NULL AUTO_INCREMENTfilm_id SMALLINTUNSIGNED NOT NULLstore_id TINYINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[inventory_id]KEY[film_id]KEY[store_id, film_id]«table»languagelanguage_id TINYINTUNSIGNED NOT NULL AUTO_INCREMENTname CHAR[20]NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[language_id]«table»paymentpayment_id SMALLINTUNSIGNED NOT NULL AUTO_INCREMENTcustomer_id SMALLINTUNSIGNED NOT NULLstaff_id TINYINTUNSIGNED NOT NULLrental_id INTDEFAULT NULLamount DECIMAL[5, 2]NOT NULLpayment_date DATETIMENOT NULLlast_update TIMESTAMPDEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[payment_id]KEY[staff_id]KEY[customer_id]«table»rentalrental_id INTNOT NULL AUTO_INCREMENTrental_date DATETIMENOT NULLinventory_id MEDIUMINTUNSIGNED NOT NULLcustomer_id SMALLINTUNSIGNED NOT NULLreturn_date DATETIMEDEFAULT NULLstaff_id TINYINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[rental_id]KEY[inventory_id]KEY[customer_id]KEY[staff_id]UNIQUE KEY[rental_date, inventory_id, customer_id]«table»staffstaff_id TINYINTUNSIGNED NOT NULL AUTO_INCREMENTfirst_name VARCHAR[45]NOT NULLlast_name VARCHAR[45]NOT NULLaddress_id SMALLINTUNSIGNED NOT NULLpicture BLOBDEFAULT NULLemail VARCHAR[50]DEFAULT NULLstore_id TINYINTUNSIGNED NOT NULLactive BOOLEANNOT NULL DEFAULT TRUEusername VARCHAR[16]NOT NULLpassword VARCHAR[40]BINARY DEFAULT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[staff_id]KEY[store_id]KEY[address_id]«table»storestore_id TINYINTUNSIGNED NOT NULL AUTO_INCREMENTmanager_staff_id TINYINTUNSIGNED NOT NULLaddress_id SMALLINTUNSIGNED NOT NULLlast_update TIMESTAMPNOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMPPK[store_id]KEY[address_id]UNIQUE KEY[manager_staff_id]n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n1n111n1n1 \ No newline at end of file diff --git a/src/Command/ImageCommand.php b/src/Command/ImageCommand.php index c8cd63d..31fb9c9 100644 --- a/src/Command/ImageCommand.php +++ b/src/Command/ImageCommand.php @@ -22,8 +22,6 @@ final class ImageCommand extends CommandAbstract private const string PLANTUML_BIN = 'bin/plantuml-mit-1.2026.6.jar'; - private const string TEMP_DIR = 'tmp'; - protected function configure(): void { $this @@ -45,8 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $image = new ImageGenerator( $this->getImageType($input), - $this->rootDir . self::PLANTUML_BIN, - $this->rootDir . self::TEMP_DIR + $this->rootDir . self::PLANTUML_BIN ); echo $image->generate($generatedPlantuml); @@ -54,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - private function getImageType(InputInterface $input): string + private function getImageType(InputInterface $input): ImageType { $imageType = ImageType::tryFrom((string) $input->getOption(self::OPTION_TYPE)); @@ -67,6 +64,6 @@ private function getImageType(InputInterface $input): string ); } - return $imageType->value; + return $imageType; } } diff --git a/src/Export/Markdown.php b/src/Export/Markdown.php index d56e7b0..1f4db89 100644 --- a/src/Export/Markdown.php +++ b/src/Export/Markdown.php @@ -23,17 +23,12 @@ public function __construct(string $template) public function export(SchemaInterface $schema): string { - $text = $this->twig->render( + return $this->twig->render( 'template', [ 'tables' => $schema->tables, 'connections' => $schema->connections, ] ); - - $text = preg_replace('/^[ \t]+/m', '', $text); - $text = preg_replace('/\n{3,}/', "\n\n", (string) $text); - - return rtrim((string) $text, "\n") . "\n"; } } diff --git a/src/Export/Plantuml.php b/src/Export/Plantuml.php index 79c91c4..34475b7 100644 --- a/src/Export/Plantuml.php +++ b/src/Export/Plantuml.php @@ -23,22 +23,12 @@ public function __construct(string $template) public function export(SchemaInterface $schema): string { - $text = $this->twig->render( + return $this->twig->render( 'template', [ 'tables' => $schema->tables, 'connections' => $schema->connections, ] ); - - $text = preg_replace('/^\s+/m', '', $text); - - return strtr( - $text, - [ - '[\t]' => "\t", - '[\n]' => '', - ] - ); } } diff --git a/src/Generator/ImageGenerator.php b/src/Generator/ImageGenerator.php index dd746c3..74eadf7 100644 --- a/src/Generator/ImageGenerator.php +++ b/src/Generator/ImageGenerator.php @@ -4,20 +4,15 @@ namespace Pongee\DatabaseSchemaVisualization\Generator; -use DateTime; use Exception; -use RuntimeException; -use SplFileObject; -use Twig\Environment; final readonly class ImageGenerator { private const int PLANTUML_LIMIT_SIZE = 16384; public function __construct( - private string $imageType, - private string $plantumlJarPath, - private string $outputFolder + private ImageType $imageType, + private string $plantumlJarPath ) { } @@ -26,56 +21,47 @@ public function __construct( */ public function generate(string $plantuml): string { - $fileName = sprintf('plantuml-%s-%s', new DateTime()->format('Y-m-d-H-i-s-u'), mt_rand()); + $command = implode( + ' ', + [ + 'java', + sprintf('-DPLANTUML_LIMIT_SIZE=%d', self::PLANTUML_LIMIT_SIZE), + '-jar', + escapeshellarg($this->plantumlJarPath), + '--pipe', + '--format', + escapeshellarg($this->imageType->value), + ] + ); + + $process = proc_open( + $command, + [ + 0 => ['pipe', 'r'], + 1 => ['pipe', 'w'], + 2 => ['pipe', 'w'], + ], + $pipes + ); - $sourceFile = new SplFileObject($this->outputFolder . '/' . $fileName . '.puml', 'w'); - $sourceFile->fwrite($plantuml); + if (!is_resource($process)) { + throw new Exception('Plantuml diagram generation failed. Unable to start the process.'); + } - $output = $this->generatePlantuml($sourceFile); + fwrite($pipes[0], $plantuml); + fclose($pipes[0]); - try { - $outputFile = new SplFileObject($this->outputFolder . '/' . $fileName . '.' . $this->imageType, 'r'); - } catch (RuntimeException $runtimeException) { - $this->deleteFiles($sourceFile); + $image = stream_get_contents($pipes[1]); + $error = stream_get_contents($pipes[2]); + fclose($pipes[1]); + fclose($pipes[2]); + if (proc_close($process) !== 0 || $image === false || $image === '') { throw new Exception( - sprintf( - 'Plantuml diagram generation failed. Original error: [%s] output: [%s]', - $runtimeException->getMessage(), - $output - ) + sprintf('Plantuml diagram generation failed. Original error: [%s]', $error) ); } - $plantumlPng = $outputFile->fread($outputFile->getSize()); - - $this->deleteFiles($sourceFile, $outputFile); - - return $plantumlPng; - } - - private function generatePlantuml(SplFileObject $sourceFile): string - { - exec( - sprintf( - 'java -DPLANTUML_LIMIT_SIZE=%s -jar %s %s -t%s -output %s 2>&1', - self::PLANTUML_LIMIT_SIZE, - $this->plantumlJarPath, - $sourceFile->getRealPath(), - escapeshellarg($this->imageType), - $this->outputFolder - ), - $output, - $return - ); - - return implode("\n", $output); - } - - private function deleteFiles(SplFileObject ...$files): void - { - foreach ($files as $file) { - unlink($file->getRealPath()); - } + return $image; } } diff --git a/src/Template/Markdown/v1.twig b/src/Template/Markdown/v1.twig index 704dc6e..0df940a 100644 --- a/src/Template/Markdown/v1.twig +++ b/src/Template/Markdown/v1.twig @@ -1,9 +1,8 @@ -# Schema +## Tables {% for table in tables %} +### `{{ table.name }}` table -## `{{ table.name }}` table - -### Columns +#### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -12,7 +11,7 @@ {% endfor -%} {% if table.primaryKey %} -### Primary Key +#### Primary Key | Columns | Parameters | | --- | --- | @@ -20,7 +19,7 @@ {% endif -%} {% if table.simpleIndexes|length %} -### Indexes +#### Indexes | Name | Columns | Parameters | | --- | --- | --- | @@ -30,7 +29,7 @@ {% endif -%} {% if table.uniqueIndexes|length %} -### Unique Indexes +#### Unique Indexes | Name | Columns | Parameters | | --- | --- | --- | @@ -40,7 +39,7 @@ {% endif -%} {% if table.fulltextIndexes|length %} -### Fulltext Indexes +#### Fulltext Indexes | Name | Columns | Parameters | | --- | --- | --- | @@ -50,7 +49,7 @@ {% endif -%} {% if table.spatialIndexes|length %} -### Spatial Indexes +#### Spatial Indexes | Name | Columns | Parameters | | --- | --- | --- | diff --git a/src/Template/Plantuml/v1.twig b/src/Template/Plantuml/v1.twig index 643fd11..e0b7430 100644 --- a/src/Template/Plantuml/v1.twig +++ b/src/Template/Plantuml/v1.twig @@ -1,117 +1,110 @@ @startuml -[\n] -!ifndef TABLE_BORDER_COLOR -!define TABLE_BORDER_COLOR Chocolate -!endif -[\n] -!ifndef TABLE_BACKGROUND_COLOR -!define TABLE_BACKGROUND_COLOR AntiqueWhite -!endif -[\n] + +!$table_border_color ?= "Chocolate" +!$table_background_color ?= "AntiqueWhite" + skinparam class { -[\t]BackgroundColor TABLE_BACKGROUND_COLOR -[\t]BorderColor TABLE_BORDER_COLOR -[\t]ArrowColor TABLE_BORDER_COLOR + BackgroundColor $table_background_color + BorderColor $table_border_color + ArrowColor $table_border_color } -[\n] + !procedure $table($name) -class "$name" << (T, TABLE_BORDER_COLOR ) >> +class "$name" <
> << (T, $table_border_color ) >> !endprocedure -[\n] + !function $key_columns($columns, $otherParameters="") -[\t]!$result = "" -[\t]!foreach $column in %splitstr($columns, ", ") -[\t][\t]!if ($result != "") -[\t][\t][\t]!$result = $result + ", " -[\t][\t]!endif -[\t][\t]!$result = $result + $column -[\t]!endfor -[\t]!if ($otherParameters != "") -[\t][\t]!$result = $result + ", " + $otherParameters -[\t]!endif -[\t]!return $result + !$result = "" + !foreach $column in %splitstr($columns, ", ") + !if ($result != "") + !$result = $result + ", " + !endif + !$result = $result + $column + !endfor + !if ($otherParameters != "") + !$result = $result + ", " + $otherParameters + !endif + !return $result !endfunction -[\n] + !procedure $primary_key($columns, $otherParameters="") -[\t]!$rendered = $key_columns($columns, $otherParameters) + !$rendered = $key_columns($columns, $otherParameters) -PK [$rendered] !endprocedure -[\n] + !procedure $column($name, $type, $otherParameters="", $comment="") -[\t]!$suffix = "" -[\t]!if ($otherParameters != "") -[\t][\t]!$suffix = $suffix + " " + $otherParameters -[\t]!endif -[\t]!if ($comment != "") -[\t][\t]!$suffix = $suffix + " COMMENT '" + $comment + "'" -[\t]!endif + !$suffix = "" + !if ($otherParameters != "") + !$suffix = $suffix + " " + $otherParameters + !endif + !if ($comment != "") + !$suffix = $suffix + " COMMENT '" + $comment + "'" + !endif +$name$type$suffix !endprocedure -[\n] + !procedure $index($columns, $otherParameters="") -[\t]!$rendered = $key_columns($columns, $otherParameters) + !$rendered = $key_columns($columns, $otherParameters) ~KEY [$rendered] !endprocedure -[\n] + !procedure $unique_index($columns, $otherParameters="") -[\t]!$rendered = $key_columns($columns, $otherParameters) + !$rendered = $key_columns($columns, $otherParameters) #UNIQUE KEY [$rendered] !endprocedure -[\n] + !procedure $fulltext_index($columns, $otherParameters="") -[\t]!$rendered = $key_columns($columns, $otherParameters) + !$rendered = $key_columns($columns, $otherParameters) #FULLTEXT KEY [$rendered] !endprocedure -[\n] + !procedure $spatial_index($columns, $otherParameters="") -[\t]!$rendered = $key_columns($columns, $otherParameters) + !$rendered = $key_columns($columns, $otherParameters) #SPATIAL KEY [$rendered] !endprocedure -[\n] + !procedure $connection_one_to_one($from, $to) -$from "1" -- "1" $to + $from "1" -- "1" $to !endprocedure -[\n] + !procedure $connection_one_to_many($from, $to) -$from "n" }-- "1" $to + $from "n" }-- "1" $to !endprocedure -[\n] + hide methods -hide stereotypes -[\n] skinparam linetype polyline left to right direction -[\n] + {% for table in tables %} - $table({{ table.name }}) { - {% for column in table.columns -%} - [\t]$column('{{ column.name }}', '{{ column.type }}{% if column.typeParameters %}[{{ column.typeParameters|join(', ') }}]{% endif %}', '{{ column.otherParameters|replace({"'": '"'})|raw }}', '{{ column.comment|replace({"'": '"'})|raw }}') - {% endfor -%} - {% if table.primaryKey %} - [\t]$primary_key('{{ table.primaryKey.columns|join(', ') }}', '{{ table.primaryKey.otherParameters|replace({"'": '"'})|raw }}') - {% endif -%} - {% for simpleIndex in table.simpleIndexes -%} - [\t]$index('{{ simpleIndex.columns|join(', ') }}', '{{ simpleIndex.otherParameters|replace({"'": '"'})|raw }}') - {% endfor -%} - {% for uniqueIndex in table.uniqueIndexes -%} - [\t]$unique_index('{{ uniqueIndex.columns|join(', ') }}', '{{ uniqueIndex.otherParameters|replace({"'": '"'})|raw }}') - {% endfor -%} - {% for fulltextIndex in table.fulltextIndexes -%} - [\t]$fulltext_index('{{ fulltextIndex.columns|join(', ') }}', '{{ fulltextIndex.otherParameters|replace({"'": '"'})|raw }}') - {% endfor -%} - {% for spatialIndex in table.spatialIndexes -%} - [\t]$spatial_index('{{ spatialIndex.columns|join(', ') }}', '{{ spatialIndex.otherParameters|replace({"'": '"'})|raw }}') - {% endfor -%} - } +$table({{ table.name }}) { +{% for column in table.columns %} + $column('{{ column.name }}', '{{ column.type }}{% if column.typeParameters %}[{{ column.typeParameters|join(', ') }}]{% endif %}', '{{ column.otherParameters|replace({"'": '"'})|raw }}', '{{ column.comment|replace({"'": '"'})|raw }}') {% endfor %} -[\n] -{% for connection in connections %} - {% if connection.type == "OneToOne" %} - $connection_one_to_one({{ connection.childTableName }}, {{ connection.parentTableName }}) - {% endif %} - {% if connection.type == "OneToMany" %} - $connection_one_to_many({{ connection.childTableName }}, {{ connection.parentTableName }}) - {% endif %} +{%- if table.primaryKey %} + $primary_key('{{ table.primaryKey.columns|join(', ') }}', '{{ table.primaryKey.otherParameters|replace({"'": '"'})|raw }}') +{% endif %} +{%- for simpleIndex in table.simpleIndexes %} + $index('{{ simpleIndex.columns|join(', ') }}', '{{ simpleIndex.otherParameters|replace({"'": '"'})|raw }}') +{% endfor %} +{%- for uniqueIndex in table.uniqueIndexes %} + $unique_index('{{ uniqueIndex.columns|join(', ') }}', '{{ uniqueIndex.otherParameters|replace({"'": '"'})|raw }}') +{% endfor %} +{%- for fulltextIndex in table.fulltextIndexes %} + $fulltext_index('{{ fulltextIndex.columns|join(', ') }}', '{{ fulltextIndex.otherParameters|replace({"'": '"'})|raw }}') +{% endfor %} +{%- for spatialIndex in table.spatialIndexes %} + $spatial_index('{{ spatialIndex.columns|join(', ') }}', '{{ spatialIndex.otherParameters|replace({"'": '"'})|raw }}') {% endfor %} -[\n] +} +{% endfor %} + +{% for connection in connections %} +{%- if connection.type == "OneToOne" %} +$connection_one_to_one({{ connection.childTableName }}, {{ connection.parentTableName }}) +{% endif %} +{%- if connection.type == "OneToMany" %} +$connection_one_to_many({{ connection.childTableName }}, {{ connection.parentTableName }}) +{% endif %} +{%- endfor %} + @enduml diff --git a/test/Unit/Export/MarkdownTest.php b/test/Unit/Export/MarkdownTest.php index 52d9530..02ab311 100644 --- a/test/Unit/Export/MarkdownTest.php +++ b/test/Unit/Export/MarkdownTest.php @@ -77,7 +77,7 @@ public function testExportTableWithColumns(SchemaInterface $schema): void $this->assertEquals( strtr( - "tables:%tables%|connections:%connections%\n", + 'tables:%tables%|connections:%connections%', [ '%tables%' => json_encode($schema->tables->jsonSerialize()), '%connections%' => json_encode($schema->connections->jsonSerialize()), diff --git a/test/Unit/Template/Markdown/V1TemplateTest.php b/test/Unit/Template/Markdown/V1TemplateTest.php index fd45d63..6da6369 100644 --- a/test/Unit/Template/Markdown/V1TemplateTest.php +++ b/test/Unit/Template/Markdown/V1TemplateTest.php @@ -42,11 +42,10 @@ public static function getSchemaProvider(): array ) ), <<<'MD' - # Schema + ## Tables + ### `actor` table - ## `actor` table - - ### Columns + #### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -89,25 +88,23 @@ public static function getSchemaProvider(): array ->addConnection(new OneToOneConnection('member_data', 'member', ['member_id'], ['id'])) ->addConnection(new OneToManyConnection('member_log', 'member', ['member_id'], ['id'])), <<<'MD' - # Schema - - ## `member` table + ## Tables + ### `member` table - ### Columns + #### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | | id | INT ( 10 ) | NOT NULL DEFAULT | - | - ### Primary Key + #### Primary Key | Columns | Parameters | | --- | --- | | id | - | + ### `member_data` table - ## `member_data` table - - ### Columns + #### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -116,28 +113,27 @@ public static function getSchemaProvider(): array | type | VARCHAR ( 64 ) | NOT NULL | - | | status | ENUM ( enabled, deleted ) | DEFAULT NULL | - | - ### Primary Key + #### Primary Key | Columns | Parameters | | --- | --- | | id | USING HASH | - ### Indexes + #### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_type | type | - | | idx_type_status | type, status | USING HASH | - ### Unique Indexes + #### Unique Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_member_id | member_id | - | + ### `member_log` table - ## `member_log` table - - ### Columns + #### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -145,31 +141,31 @@ public static function getSchemaProvider(): array | member_id | INT ( 10 ) | NOT NULL | - | | created_at | DATETIME | NOT NULL | - | - ### Primary Key + #### Primary Key | Columns | Parameters | | --- | --- | | id | USING HASH | - ### Indexes + #### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_action | action | - | - ### Unique Indexes + #### Unique Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_member_id | member_id | USING HASH | - ### Fulltext Indexes + #### Fulltext Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_member_id_action | member_id, action | - | - ### Spatial Indexes + #### Spatial Indexes | Name | Columns | Parameters | | --- | --- | --- | @@ -199,11 +195,10 @@ public static function getSchemaProvider(): array ->addSpatialIndex(new SpatialIndex('idx_area', ['area'])) ), <<<'MD' - # Schema - - ## `measurement` table + ## Tables + ### `measurement` table - ### Columns + #### Columns | Name | Type | Parameters | Comment | | --- | --- | --- | --- | @@ -214,19 +209,19 @@ public static function getSchemaProvider(): array | embedding | VECTOR ( 3 ) | NOT NULL | - | | label | VARCHAR ( 64 ) | - | - | - ### Primary Key + #### Primary Key | Columns | Parameters | | --- | --- | | sensor_id, id | - | - ### Indexes + #### Indexes | Name | Columns | Parameters | | --- | --- | --- | | idx_sensor_score_label | sensor_id, score, label | - | - ### Spatial Indexes + #### Spatial Indexes | Name | Columns | Parameters | | --- | --- | --- |