jardistools/dbschema

Database schema introspection and DDL export for MySQL, MariaDB, PostgreSQL, and SQLite

Maintainers

Package info

github.com/jardisTools/dbSchema

Homepage

Issues

pkg:composer/jardistools/dbschema

Statistics

Installs: 22

Dependents: 0

Suggesters: 0

Stars: 0

v1.0.0 2026-03-31 08:10 UTC

This package is auto-updated.

Last update: 2026-03-31 08:11:08 UTC


README

Build Status License: PolyForm Shield PHP Version PHPStan Level PSR-12 Coverage

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 TABLE SQL 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 MappingfieldType() 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:

jardis.io/docs/tools/dbschema

License

This package is licensed under the PolyForm Shield License 1.0.0. Free for all use except building competing frameworks or developer tooling.

Jardis · Documentation · Headgent