Browse Source

[DOCUMENTATION] Add database diagram to developer documentation

v3
Hugo Sales 5 months ago
parent
commit
cfe842b487
Signed by: someonewithpc <hugo@hsal.es> GPG Key ID: 7D0C7EAFC9D835A0
6 changed files with 1551 additions and 16 deletions
  1. BIN
      DOCUMENTATION/DEVELOPERS/database/database.pdf
  2. +22
    -16
      bin/generate_entity_diagrams
  3. +1
    -0
      docs/developer/src/SUMMARY.md
  4. +3
    -0
      docs/developer/src/database.md
  5. +1525
    -0
      docs/developer/src/database/database.dot
  6. BIN
      docs/developer/src/database/database.pdf

BIN
DOCUMENTATION/DEVELOPERS/database/database.pdf View File


+ 22
- 16
bin/generate_entity_diagrams View File

@@ -1,4 +1,4 @@
#!/usr/local/bin/php
#!/usr/bin/env php

<?php

@@ -6,7 +6,7 @@ define('INSTALL_DIR', dirname(__DIR__));

require INSTALL_DIR . '/vendor/autoload.php';

use App\Util\Common;
use App\Util\Formatting;
use App\Util\HTML as H;
use Functional as F;

@@ -24,13 +24,22 @@ $files = glob(INSTALL_DIR . '/src/Entity/*.php');

$tables = [];
$edges = [];
$classes = [];
foreach ($files as $file) {
require_once $file;

$class = '';
$declared = get_declared_classes();
$class = end($declared);
foreach ($declared as $dc) {
if (preg_match('/^(App|(Component|Plugin)\\\\[^\\\\]+)\\\\Entity/', $dc) && !in_array($dc, $classes)) {
$class = $dc;
$classes[] = $class;
break;
}
}

$schema = $class::schemaDef();
$table = $schema['name'];
$table = preg_replace(',`?([^`]+)`?,', '$1', $schema['name']);
$fields = [['name' => $table, 'type' => '']];
foreach ($schema['fields'] as $name => $opts) {
$fields[] = [
@@ -39,14 +48,11 @@ foreach ($files as $file) {
];
}

if (isset($schema['foreign keys'])) {
foreach ($schema['foreign keys'] as $name => $map) {
// Patern matching like above would be nice
list($foreign_table,
$keys) = $map;
$local_key = array_keys($keys)[0];
$foreign_key = $keys[$local_key];
$edges[] = "{$table}:{$local_key} -- {$foreign_table}:{$foreign_key}";
foreach ($schema['fields'] as $field => $opts) {
if (isset($opts['foreign key'])) {
[$foreign_entity, $foreign_key] = explode('.', $opts['target']);
$foreign_table = Formatting::camelCaseToSnakeCase(preg_replace('/GSActor/', 'gsactor', $foreign_entity));
$edges[] = "{$table}:{$field} -- {$foreign_table}:{$foreign_key}";
}
}

@@ -59,12 +65,12 @@ foreach ($files as $file) {
F\map($fields, $cell)),
];

$tables[] = Common::indent("{$table} [shape=none, label=<\n" . Common::indent(H::html($html)) . "\n>]");
$tables[] = Formatting::indent("{$table} [shape=none, label=<\n" . Formatting::indent(H::html($html)) . "\n>]");
}

$replace = [
'/%tables%/' => Common::indent(implode("\n", $tables)),
'/%edges%/' => Common::indent(implode("\n", $edges)),
'/%tables%/' => Formatting::indent(implode("\n", $tables)),
'/%edges%/' => Formatting::indent(implode("\n", $edges)),
// '/_/' => '\textunderscore ',
];

@@ -73,7 +79,7 @@ foreach ($replace as $from => $to) {
$out = preg_replace($from, $to, $out);
}

$path = dirname(__DIR__) . '/DOCUMENTATION/database';
$path = dirname(__DIR__) . '/docs/developer/src/database';

$outfile = $path . '/database.dot';
file_put_contents($outfile, $out);


+ 1
- 0
docs/developer/src/SUMMARY.md View File

@@ -2,6 +2,7 @@

- [High level view](./high_level.md)
- [Architecture and Paradigms](./architecture.md)
- [Database](./database.md)
- [Plugins](./plugins.md)
- [Event Handlers](./plugins/no_docker_shell.md)
- [Installation](./plugins/docker_web.md)


+ 3
- 0
docs/developer/src/database.md View File

@@ -0,0 +1,3 @@
# Database

Checkout a visual diagram of the database tables at docs/developer/src/database/database.pdf

+ 1525
- 0
docs/developer/src/database/database.dot
File diff suppressed because it is too large
View File


BIN
docs/developer/src/database/database.pdf View File


Loading…
Cancel
Save