PHPackages                             phauthentic/symfony-doctrine-schema-loader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. phauthentic/symfony-doctrine-schema-loader

ActiveLibrary[Database &amp; ORM](/categories/database)

phauthentic/symfony-doctrine-schema-loader
==========================================

057↓91.7%PHPCI passing

Since Mar 14Pushed 3mo agoCompare

[ Source](https://github.com/Phauthentic/symfony-doctrine-schema-loader)[ Packagist](https://packagist.org/packages/phauthentic/symfony-doctrine-schema-loader)[ RSS](/packages/phauthentic-symfony-doctrine-schema-loader/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Symfony Doctrine Schema Loader
==============================

[](#symfony-doctrine-schema-loader)

Define database schemas programmatically in PHP classes and generate Doctrine Migrations from them.

This library lets you define tables, columns, indexes, and foreign keys in `*Schema.php` classes instead of using ORM entities or manual migration files. The schema loader discovers these classes across configured paths, merges their definitions, and provides a `SchemaProvider` for Doctrine Migrations—so running `migrations:diff` produces a migration file that brings your database in sync with your programmatic schema.

**When to use this** – Use this library when you work without Doctrine ORM (e.g. plain DBAL, raw SQL, or a custom data layer) and want a modular setup where each module or capability contributes its own schema definitions. The loader discovers `*Schema.php` files via paths or glob patterns, so modules can ship their schemas alongside their code and migrations stay in sync automatically.

Requirements
------------

[](#requirements)

- PHP 8.4+
- Symfony 7.4 or 8.0 (doctrine-bridge)
- Doctrine DBAL 4.4+
- Doctrine Migrations 3.9+

Usage
-----

[](#usage)

```
composer require phauthentic/symfony-doctrine-schema-loader
```

Schema Definition Interface
---------------------------

[](#schema-definition-interface)

Implement `SchemaDefinitionInterface` in classes that define database objects. Each class receives a `Schema` instance and adds tables, sequences, and other objects via the Doctrine DBAL Schema API.

```
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Phauthentic\SymfonyDoctrineSchemaLoader\Schema\SchemaDefinitionInterface;

final class UserSchema implements SchemaDefinitionInterface
{
    public function define(Schema $schema): void
    {
        $table = $schema->createTable('user');
        $table->addColumn('id', Types::INTEGER)
            ->setAutoincrement(true)
            ->setNotnull(true);
        $table->addColumn('email', Types::STRING, ['length' => 255])
            ->setNotnull(true);
        $table->setPrimaryKey(['id']);
    }
}
```

You can extend `AbstractSchemaDefinition` for a no-op base implementation.

Schema Loader
-------------

[](#schema-loader)

`SchemaLoader` implements `SchemaLoaderInterface` and scans directories recursively for PHP files matching `*Schema.php` (or a custom suffix), loads classes implementing `SchemaDefinitionInterface`, and merges their definitions into a single `Schema`. Depend on `SchemaLoaderInterface` when you need to inject a schema loader.

```
use Phauthentic\SymfonyDoctrineSchemaLoader\Loader\SchemaLoader;

$loader = new SchemaLoader([
    'src/Capability/Alpha/Infrastructure/Persistence/Doctrine/Schema',
    'src/Capability/Beta/Infrastructure/Persistence/Doctrine/Schema',
]);

$schema = $loader->load();

// With glob pattern (discovers all matching directories)
$loader = new SchemaLoader([
    'src/Capability/*/Infrastructure/Persistence/Doctrine/Schema',
]);
$schema = $loader->load();
```

Doctrine Migrations Integration
-------------------------------

[](#doctrine-migrations-integration)

`LoaderSchemaProvider` implements `Doctrine\Migrations\Provider\SchemaProvider` and delegates to `SchemaLoader`. Wire it into Doctrine Migrations so the diff command uses your programmatic schemas instead of ORM metadata.

```
use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Provider\SchemaProvider;
use Phauthentic\SymfonyDoctrineSchemaLoader\Loader\SchemaLoader;
use Phauthentic\SymfonyDoctrineSchemaLoader\Provider\LoaderSchemaProvider;

$loader = new SchemaLoader($paths);
$provider = new LoaderSchemaProvider($loader);

$dependencyFactory->setService(SchemaProvider::class, $provider);
```

Symfony Integration
-------------------

[](#symfony-integration)

When using `doctrine/doctrine-migrations-bundle`, register the provider as a service and inject it into the migrations dependency factory:

```
# config/services.yaml
services:
    Phauthentic\SymfonyDoctrineSchemaLoader\Loader\SchemaLoader:
        arguments:
            $paths:
                - '%kernel.project_dir%/src/Capability/Alpha/Infrastructure/Persistence/Doctrine/Schema'
                - '%kernel.project_dir%/src/Capability/Beta/Infrastructure/Persistence/Doctrine/Schema'

    Phauthentic\SymfonyDoctrineSchemaLoader\Provider\LoaderSchemaProvider:
        arguments:
            $loader: '@Phauthentic\SymfonyDoctrineSchemaLoader\Loader\SchemaLoader'
```

Then configure the bundle to use your provider (e.g. via a compiler pass or by setting `SchemaProvider::class` in the dependency factory before it is frozen).

Why Programmatic Schemas?
-------------------------

[](#why-programmatic-schemas)

- **No ORM required** – Define schemas without Doctrine ORM entities.
- **Modular** – Organize schema definitions by capability or bounded context.
- **Testable** – Schema classes are plain PHP; easy to unit test.
- **Explicit** – Tables and columns are defined in one place, close to the code that uses them.

License
-------

[](#license)

This library is under the MIT license.

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance54

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4996022?v=4)[Florian Krämer](/maintainers/floriankraemer)[@floriankraemer](https://github.com/floriankraemer)

---

Top Contributors

[![floriankraemer](https://avatars.githubusercontent.com/u/4996022?v=4)](https://github.com/floriankraemer "floriankraemer (10 commits)")

---

Tags

doctrinedoctrine-dbalmodularityschemasymfony

### Embed Badge

![Health badge](/badges/phauthentic-symfony-doctrine-schema-loader/health.svg)

```
[![Health](https://phpackages.com/badges/phauthentic-symfony-doctrine-schema-loader/health.svg)](https://phpackages.com/packages/phauthentic-symfony-doctrine-schema-loader)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
