jardistools / dbschema
Database schema introspection and DDL export for MySQL, MariaDB, PostgreSQL, and SQLite
v1.0.0
2026-03-31 08:10 UTC
Requires
- php: >=8.2
- ext-pdo: *
- jardissupport/contract: ^1.0
- jardissupport/dotenv: ^1.0
Requires (Dev)
- phpstan/phpstan: ^2.0.4
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.11.2
This package is auto-updated.
Last update: 2026-03-31 08:11:08 UTC
README
Part of the Jardis Business Platform — Enterprise-grade PHP components for Domain-Driven Design
Database schema introspection and DDL export. Reads table structures, columns, indexes, and foreign keys from live databases via PDO. Exports to SQL (CREATE TABLE), JSON, or PHP arrays. Dialect-aware for MySQL, MariaDB, PostgreSQL, and SQLite.
Features
- Schema Introspection — reads tables, columns, indexes, and foreign keys from a live database
- DDL Export — generates
CREATE TABLESQL scripts with dialect-correct syntax - JSON Export — structured JSON output suitable for storage, diffing, or feeding the Jardis Builder
- Array Export — PHP array representation for programmatic processing
- Multi-Database — MySQL, MariaDB, PostgreSQL, and SQLite via automatic PDO driver detection
- Abstract Type Mapping —
fieldType()normalises driver-specific column types to portable abstract types - Field Type Normalization — consistent column metadata regardless of database vendor
Installation
composer require jardistools/dbschema
Quick Start
use JardisTools\DbSchema\DbSchemaReader; use JardisTools\DbSchema\DbSchemaExporter; $pdo = new PDO('mysql:host=localhost;dbname=shop', 'user', 'pass'); $reader = new DbSchemaReader($pdo); $exporter = new DbSchemaExporter($reader); // List all tables $tables = $reader->tables(); // Export schema as JSON (suitable for Jardis Builder input) $json = $exporter->toJson($tables, prettyPrint: true); file_put_contents('schema.json', $json);
Advanced Usage
use JardisTools\DbSchema\DbSchemaReader; use JardisTools\DbSchema\DbSchemaExporter; $pdo = new PDO('pgsql:host=localhost;dbname=shop', 'user', 'pass'); $reader = new DbSchemaReader($pdo); // Inspect a single table $columns = $reader->columns('orders'); $indexes = $reader->indexes('orders'); $foreignKeys = $reader->foreignKeys('orders'); // Translate a driver-specific type to a portable abstract type $abstractType = $reader->fieldType('character varying'); // → 'string' // Export selected tables as SQL DDL $exporter = new DbSchemaExporter($reader); $ddl = $exporter->toSql(['orders', 'order_lines', 'customers']); echo $ddl; // CREATE TABLE "orders" ( ... ); // CREATE TABLE "order_lines" ( ... ); // Export as PHP array for custom processing $schema = $exporter->toArray(['orders', 'order_lines']); // [ // 'version' => '1.0', // 'generated' => '2025-01-16 10:30:00', // 'tables' => ['orders' => ['columns' => [...], 'indexes' => [...], 'foreignKeys' => [...]]] // ] // Feed directly into the Jardis Builder use JardisTools\Builder\Config\DatabaseSchema; $databaseSchema = DatabaseSchema::fromArray($schema);
Documentation
Full documentation, guides, and API reference:
License
This package is licensed under the PolyForm Shield License 1.0.0. Free for all use except building competing frameworks or developer tooling.