diff --git a/.docker/php/Dockerfile b/.docker/php/Dockerfile
index 73ede6d8..53501f67 100755
--- a/.docker/php/Dockerfile
+++ b/.docker/php/Dockerfile
@@ -64,6 +64,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends default-mysql-c
#MONGODB
RUN pecl install mongodb-1.17.2 && docker-php-ext-enable mongodb
+#Graphviz
+RUN apt-get update && apt-get install -y --no-install-recommends graphviz
+
ARG PUID=1000
ARG PGID=1000
diff --git a/Makefile b/Makefile
index 90639c1d..4a0978ad 100644
--- a/Makefile
+++ b/Makefile
@@ -31,3 +31,5 @@ composer-normalize:
sudo chmod a+x composer-normalize
docker-compose exec php php composer-normalize
+generate-artifact:
+ docker-compose exec php composer generate:artifact
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 74efcf40..b099e445 100644
--- a/composer.json
+++ b/composer.json
@@ -293,6 +293,10 @@
"test:run:coverage": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/phpunit --coverage-html ./tmp/phpunit/report"
+ ],
+ "generate:artifact": [
+ "Composer\\Config::disableProcessTimeout",
+ "bin/console draw:doctrine:generate-graph-schema | dot -Tsvg -o doc/databse.svg"
]
},
"minimum-stability": "dev",
diff --git a/doc/databse.svg b/doc/databse.svg
new file mode 100644
index 00000000..36f147fc
--- /dev/null
+++ b/doc/databse.svg
@@ -0,0 +1,926 @@
+
+
+
+
+
diff --git a/packages/doctrine-extra/ORM/Command/GenerateGraphSchemaCommand.php b/packages/doctrine-extra/ORM/Command/GenerateGraphSchemaCommand.php
new file mode 100644
index 00000000..9c4ac595
--- /dev/null
+++ b/packages/doctrine-extra/ORM/Command/GenerateGraphSchemaCommand.php
@@ -0,0 +1,75 @@
+setName('draw:doctrine:generate-graph-schema')
+ ->setDescription('Get dot from database schema.')
+ ->setHelp(\sprintf('Usage: bin/console %s | dot -Tsvg -o /tmp/databse.svg', $this->getName()))
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int
+ {
+ $io = new SymfonyStyle($input, $output);
+ $io->writeln($this->getDot());
+
+ return Command::SUCCESS;
+ }
+
+ /**
+ * Get dot from database schema.
+ */
+ protected function getDot(): string
+ {
+ /** @var array> $metadata */
+ $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
+
+ usort($metadata, static fn (ClassMetadata $a, ClassMetadata $b): int => $a->getTableName() <=> $b->getTableName());
+
+ $tool = new SchemaTool($this->entityManager);
+ $schema = $tool->getSchemaFromMetadata($metadata);
+
+ $visitor = new Graphviz();
+
+ $visitor->acceptSchema($schema);
+
+ foreach ($schema->getTables() as $table) {
+ $visitor->acceptTable($table);
+ foreach ($table->getColumns() as $column) {
+ $visitor->acceptColumn($table, $column);
+ }
+ foreach ($table->getIndexes() as $index) {
+ $visitor->acceptIndex($table, $index);
+ }
+ foreach ($table->getForeignKeys() as $foreignKey) {
+ $visitor->acceptForeignKey($table, $foreignKey);
+ }
+ }
+
+ foreach ($schema->getSequences() as $sequence) {
+ $visitor->acceptSequence($sequence);
+ }
+
+ return $visitor->getOutput();
+ }
+}
diff --git a/packages/doctrine-extra/Tests/DependencyInjection/DoctrineExtraIntegrationTest.php b/packages/doctrine-extra/Tests/DependencyInjection/DoctrineExtraIntegrationTest.php
index 7320b5a8..10b271ff 100644
--- a/packages/doctrine-extra/Tests/DependencyInjection/DoctrineExtraIntegrationTest.php
+++ b/packages/doctrine-extra/Tests/DependencyInjection/DoctrineExtraIntegrationTest.php
@@ -8,6 +8,7 @@
use Draw\Component\DependencyInjection\Integration\Test\IntegrationTestCase;
use Draw\Component\DependencyInjection\Integration\Test\ServiceConfiguration;
use Draw\DoctrineExtra\DependencyInjection\DoctrineExtraIntegration;
+use Draw\DoctrineExtra\ORM\Command\GenerateGraphSchemaCommand;
use Draw\DoctrineExtra\ORM\Command\MysqlDumpCommand;
use Draw\DoctrineExtra\ORM\Command\MysqlImportFileCommand;
use Draw\DoctrineExtra\ORM\EntityHandler;
@@ -76,6 +77,12 @@ public static function provideTestLoad(): iterable
MysqlDumpCommand::class,
]
),
+ new ServiceConfiguration(
+ 'draw.doctrine_extra.orm.command.generate_graph_schema_command',
+ [
+ GenerateGraphSchemaCommand::class,
+ ]
+ ),
],
[
'doctrine' => [
diff --git a/tests/DoctrineExtra/ORM/Command/GenerateGraphSchemaCommandTest.php b/tests/DoctrineExtra/ORM/Command/GenerateGraphSchemaCommandTest.php
new file mode 100644
index 00000000..20b9befe
--- /dev/null
+++ b/tests/DoctrineExtra/ORM/Command/GenerateGraphSchemaCommandTest.php
@@ -0,0 +1,52 @@
+execute([])
+ ->test(
+ CommandDataTester::create()
+ ->setExpectedDisplay(null)
+ )
+ ;
+ }
+}