PHPackages                             mnapoli/dbal-schema - 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. mnapoli/dbal-schema

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

mnapoli/dbal-schema
===================

DB schema manager for Doctrine DBAL

1.3.1(2y ago)9732.9k↓75%71MITPHPPHP &gt;=8.0

Since Mar 24Pushed 2y ago3 watchersCompare

[ Source](https://github.com/mnapoli/dbal-schema)[ Packagist](https://packagist.org/packages/mnapoli/dbal-schema)[ GitHub Sponsors](https://github.com/mnapoli)[ RSS](/packages/mnapoli-dbal-schema/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (4)Versions (12)Used By (1)

A schema manager for [Doctrine DBAL](http://www.doctrine-project.org/projects/dbal.html): all the convenience of the Doctrine ORM, without using the ORM.

Why?
----

[](#why)

Doctrine ORM can automatically manage your DB schema based on your entity mapping. This feature is lost when using the DBAL instead of the ORM.

This package lets you achieve something similar by defining your DB schema with PHP code. It also lets you manage your database using a Symfony Console command similar to Symfony's native `doctrine:schema:update` command, as well as DB migrations.

Installation
------------

[](#installation)

```
composer require mnapoli/dbal-schema
```

Usage
-----

[](#usage)

### 1. Define a schema

[](#1-define-a-schema)

Define your DB schema by implementing the `SchemaDefinition` interface:

```
class MySchemaDefinition implements \DbalSchema\SchemaDefinition
{
    public function define(Schema $schema)
    {
        $usersTable = $schema->createTable('users');
        $usersTable->addColumn('id', 'integer');
        $usersTable->addColumn('email', 'string');
        $usersTable->addColumn('lastLogin', 'datetime');
        $usersTable->addColumn('score', 'float', [
            'notnull' => false,
        ]);
        $usersTable->setPrimaryKey(['id']);
        $usersTable->addUniqueIndex(['email']);
    }
}
```

You can read the whole API available on [Doctrine's documentation](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-representation.html).

### 2. Set up the schema

[](#2-set-up-the-schema)

Doctrine can now generate/update your database based on your schema.

#### Using Symfony

[](#using-symfony)

Here is an example of configuration that can go in your `config/services.yml`:

```
services:

    DbalSchema\SchemaDefinition:
        # Replace this with your class name
        alias: App\Database\MySchemaDefinition
    DbalSchema\DbalSchemaProvider:
    # Register the commands:
    DbalSchema\DbalSchemaCommand:
    DbalSchema\Command\UpdateCommand:
    DbalSchema\Command\PurgeCommand:
```

This configuration assumes your services are autowired.

Once the services are registered, you can now run the commands:

```
bin/console dbal:schema:update
bin/console dbal:schema:purge
```

#### Using [Silly](https://github.com/mnapoli/silly)

[](#using-silly)

Using Silly you can ignore the many separate command classes and simply use the `DbalSchemaCommand` class:

```
$schema = new MySchemaDefinition();
$dbalConnection = /* your DBAL connection, see http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html */

$command = new DbalSchemaCommand($dbalConnection, $schema);

$application = new Silly\Application();
$application->command('db [--force]', [$command, 'update']);
$application->command('db-purge [--force]', [$command, 'purge']);
$application->run();
```

If you are using the [Silly PHP-DI edition](https://github.com/mnapoli/silly/blob/master/docs/php-di.md) it's even simpler as [PHP-DI](http://php-di.org/) can instantiate the `DbalSchemaCommand` service:

```
$application->command('db [--force]', [DbalSchemaCommand::class, 'update']);
$application->command('db-purge [--force]', [DbalSchemaCommand::class, 'purge']);
```

### 3. Optional: database migrations

[](#3-optional-database-migrations)

If you prefer using database migrations instead of running `bin/console dbal:schema:update`, DBAL Schema integrates with Doctrine Migrations.

To set it up, we need the `setService()` method call to happen like in the example below:

```
use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Provider\SchemaProvider;
use DbalSchema\DbalSchemaProvider;

$doctrineMigrationDependencyFactory = DependencyFactory::fromConnection(...);

$doctrineMigrationDependencyFactory->setService(SchemaProvider::class, new DbalSchemaProvider(new MySchemaDefinition()));
```

In Symfony, it can be done by installing the [DoctrineMigrationsBundle](https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html) and editing `config/packages/doctrine_migrations.yaml`:

```
doctrine_migrations:
    # ...
    services:
        Doctrine\Migrations\Provider\SchemaProvider: DbalSchema\DbalSchemaProvider
```

Now, you can run:

```
bin/console doctrine:migrations:diff
```

to generate migrations based on your DBAL schema.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 59.6% 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.

###  Release Activity

Cadence

Every ~246 days

Recently: every ~277 days

Total

11

Last Release

880d ago

Major Versions

0.2.1 → 1.0.02017-12-23

PHP version history (3 changes)0.1.0PHP ^7.0

1.1.0PHP &gt;=7.4

1.2.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/329a6111724074f5388e95dd41a03ccf3c43f4bfe1ecf27c94c9efc6f7823228?d=identicon)[mnapoli](/maintainers/mnapoli)

---

Top Contributors

[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (28 commits)")[![ddeboer](https://avatars.githubusercontent.com/u/89267?v=4)](https://github.com/ddeboer "ddeboer (5 commits)")[![andersonamuller](https://avatars.githubusercontent.com/u/1681800?v=4)](https://github.com/andersonamuller "andersonamuller (3 commits)")[![frenchcomp](https://avatars.githubusercontent.com/u/1397905?v=4)](https://github.com/frenchcomp "frenchcomp (3 commits)")[![smoench](https://avatars.githubusercontent.com/u/183530?v=4)](https://github.com/smoench "smoench (2 commits)")[![jdreesen](https://avatars.githubusercontent.com/u/424602?v=4)](https://github.com/jdreesen "jdreesen (2 commits)")[![ruudk](https://avatars.githubusercontent.com/u/104180?v=4)](https://github.com/ruudk "ruudk (2 commits)")[![jeremyb](https://avatars.githubusercontent.com/u/134588?v=4)](https://github.com/jeremyb "jeremyb (1 commits)")[![lex111](https://avatars.githubusercontent.com/u/4408379?v=4)](https://github.com/lex111 "lex111 (1 commits)")

---

Tags

db-schemadoctrinedoctrine-dbalphpschemadoctrinedbaldb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mnapoli-dbal-schema/health.svg)

```
[![Health](https://phpackages.com/badges/mnapoli-dbal-schema/health.svg)](https://phpackages.com/packages/mnapoli-dbal-schema)
```

###  Alternatives

[doctrine/doctrine-migrations-bundle

Symfony DoctrineMigrationsBundle

4.3k177.9M537](/packages/doctrine-doctrine-migrations-bundle)[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[jawira/db-draw

📐 Takes a DoctrineORM connection and generates a database diagram in .puml format

2295.1k2](/packages/jawira-db-draw)[flow-php/doctrine-dbal-bulk

Bulk inserts and updates for Doctrine DBAL

14295.2k1](/packages/flow-php-doctrine-dbal-bulk)[vasek-purchart/doctrine-date-time-immutable-types-bundle

Bundle integration of Doctrine DateTimeImmutable types for Symfony

1085.6k](/packages/vasek-purchart-doctrine-date-time-immutable-types-bundle)

PHPackages © 2026

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