PHPackages                             thecodingmachine/dbal-fluid-schema-builder - 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. thecodingmachine/dbal-fluid-schema-builder

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

thecodingmachine/dbal-fluid-schema-builder
==========================================

Build and modify your database schema using Doctrine DBAL and a fluid syntax.

v2.0.1(2y ago)28189.8k↓28.6%4[1 issues](https://github.com/thecodingmachine/dbal-fluid-schema-builder/issues)3MITPHPPHP ^7.4 || ^8.0CI failing

Since Jun 5Pushed 2y ago6 watchersCompare

[ Source](https://github.com/thecodingmachine/dbal-fluid-schema-builder)[ Packagist](https://packagist.org/packages/thecodingmachine/dbal-fluid-schema-builder)[ RSS](/packages/thecodingmachine-dbal-fluid-schema-builder/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (4)Versions (14)Used By (3)

[![Latest Stable Version](https://camo.githubusercontent.com/06572f1334a30fe13f32d60eae4fd5e1b296df4fe46f769b38b0aa01a618103b/68747470733a2f2f706f7365722e707567782e6f72672f746865636f64696e676d616368696e652f6462616c2d666c7569642d736368656d612d6275696c6465722f762f737461626c65)](https://packagist.org/packages/thecodingmachine/dbal-fluid-schema-builder)[![Total Downloads](https://camo.githubusercontent.com/70cad9e85397bf877039b9dd8aadcc7db2d753b59cfb39e6534d9cf40354b88d/68747470733a2f2f706f7365722e707567782e6f72672f746865636f64696e676d616368696e652f6462616c2d666c7569642d736368656d612d6275696c6465722f646f776e6c6f616473)](https://packagist.org/packages/thecodingmachine/dbal-fluid-schema-builder)[![Latest Unstable Version](https://camo.githubusercontent.com/35e217ab3fa383a8f9a76594316d87751b4fd5610fdea02c23c9ed2815ccc61f/68747470733a2f2f706f7365722e707567782e6f72672f746865636f64696e676d616368696e652f6462616c2d666c7569642d736368656d612d6275696c6465722f762f756e737461626c65)](https://packagist.org/packages/thecodingmachine/dbal-fluid-schema-builder)[![License](https://camo.githubusercontent.com/fbaf34150f645cf0308023ef5f6a4758c2622933e1d69fab786c1501135e6d4a/68747470733a2f2f706f7365722e707567782e6f72672f746865636f64696e676d616368696e652f6462616c2d666c7569642d736368656d612d6275696c6465722f6c6963656e7365)](https://packagist.org/packages/thecodingmachine/dbal-fluid-schema-builder)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/257880638c4681a9e3fbd516e4baedfea2bb6a3c8fdd97cf2034756f2e539e42/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f746865636f64696e676d616368696e652f6462616c2d666c7569642d736368656d612d6275696c6465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/thecodingmachine/dbal-fluid-schema-builder/?branch=master)[![Build Status](https://camo.githubusercontent.com/6b967486a4081a70f44f5192c03254a40dddde18aee569a6fe406a55787af396/68747470733a2f2f7472617669732d63692e6f72672f746865636f64696e676d616368696e652f6462616c2d666c7569642d736368656d612d6275696c6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/thecodingmachine/dbal-fluid-schema-builder)[![Coverage Status](https://camo.githubusercontent.com/dc8d6914ed6acb6b8107e431c96f8173a3882ab7f69e4d5cbaaa0bb584319dba/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f746865636f64696e676d616368696e652f6462616c2d666c7569642d736368656d612d6275696c6465722f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/thecodingmachine/dbal-fluid-schema-builder?branch=master)

Fluid schema builder for Doctrine DBAL
======================================

[](#fluid-schema-builder-for-doctrine-dbal)

Build and modify your database schema using [DBAL](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-representation.html) and a fluid syntax.

[![Screencast](doc/images/screencast.gif)](doc/images/screencast.gif)

Why?
----

[](#why)

Doctrine DBAL provides a powerful API to alter your database schema. This library is a wrapper around the DBAL standard API to provide a shorter, quicker syntax for day-to-day use. It provides shortcuts and syntactic sugars to make you efficient.

### IDE friendly

[](#ide-friendly)

You can use the autocomplete of your preferred IDE (PHPStorm, Eclipse PDT, Netbeans...) to build your schema easily. No need to look at the docs anymore!

### Static code analysis

[](#static-code-analysis)

Your favorite static PHP code analyzer (Scrutinizer, PHPStan...) can catch errors for you! For instance, each database type is a PHP method, so no typos anymore in the column type - ... was it 'INT' or 'INTEGER' already? :)

Why not?
--------

[](#why-not)

The fluid schema builders aims at solving the cases you encounter in 99% of your schemas in a concise way. It does not cover the whole possible use cases and there is no aim to target that goal.

For instance, if you have foreign keys on several columns, you cannot use `FluidSchema`. You should fallback to classic DBAL.

Comparison with DBAL "native" API
---------------------------------

[](#comparison-with-dbal-native-api)

Instead of:

```
$table = $schema->createTable('posts');
$table->addColumn('id', 'integer');
$table->addColumn('description', 'string', [
    'length' => 50,
    'notnull' => false,
]);
$table->addColumn('user_id', 'integer');
$table->setPrimaryKey(['id']);
$table->addForeignKeyConstraint('users', ['user_id'], ['id']);
```

you write:

```
$db = new FluidSchema($schema);

$posts = $db->table('posts');

$posts->id() // Let's create a default autoincremented ID column
      ->column('description')->string(50)->null() // Let's create a 'description' column
      ->column('user_id')->references('users');   // Let's create a foreign key.
                                                  // We only specify the table name.
                                                  // FluidSchema infers the column type and the "remote" column.
```

Features
--------

[](#features)

FluidSchema does its best to make your life easier.

**Tables and column types**

```
$table = $db->table('foo');

// Supported types
$table->column('xxxx')->string(50)              // VARCHAR(50)
      ->column('xxxx')->integer()
      ->column('xxxx')->float()
      ->column('xxxx')->text()                  // Long string
      ->column('xxxx')->boolean()
      ->column('xxxx')->smallInt()
      ->column('xxxx')->bigInt()
      ->column('xxxx')->decimal(10, 2)          // DECIMAL(10, 2)
      ->column('xxxx')->guid()
      ->column('xxxx')->binary(255)
      ->column('xxxx')->blob()                  // Long binary
      ->column('xxxx')->date()
      ->column('xxxx')->datetime()
      ->column('xxxx')->datetimeTz()
      ->column('xxxx')->time()
      ->column('xxxx')->dateImmutable()         // From Doctrine DBAL 2.6+
      ->column('xxxx')->datetimeImmutable()     // From Doctrine DBAL 2.6+
      ->column('xxxx')->datetimeTzImmutable()   // From Doctrine DBAL 2.6+
      ->column('xxxx')->timeImmutable()         // From Doctrine DBAL 2.6+
      ->column('xxxx')->dateInterval()          // From Doctrine DBAL 2.6+
      ->column('xxxx')->array()
      ->column('xxxx')->simpleArray()
      ->column('xxxx')->json()                  // From Doctrine DBAL 2.6+
      ->column('xxxx')->jsonArray()             // Deprecated in Doctrine DBAL 2.6+
      ->column('xxxx')->object();               // Serialized PHP object
```

**Shortcut methods:**

```
// Create an 'id' primary key that is an autoincremented integer
$table->id();

// Don't like autincrements? No problem!
// Create an 'uuid' primary key that is of the DBAL 'guid' type
$table->uuid();

// Create "created_at" and "updated_at" columns
$table->timestamps();
```

**Creating indexes:**

```
// Directly on a column:
$table->column('login')->string(50)->index();

// Or on the table object (if there are several columns to add to an index):
$table->index(['category1', 'category2']);
```

**Creating unique indexes:**

```
// Directly on a column:
$table->column('login')->string(50)->unique();

// Or on the table object (if there are several columns to add to the constraint):
$table->unique(['login', 'status']);
```

**Make a column nullable:**

```
$table->column('description')->string(50)->null();
```

**Set the default value of a column:**

```
$table->column('enabled')->bool()->default(true);
```

**Create a foreign key**

```
$table->column('country_id')->references('countries');
```

**Note:** The foreign key will be automatically created on the primary table of the table "countries". The type of the "country\_id" column will be exactly the same as the type of the primary key of the "countries" table.

**Create a jointure table (aka associative table) between 2 tables:**

```
$db->junctionTable('users', 'roles');

// This will create a 'users_roles' table with 2 foreign keys:
//  - 'user_id' pointing on the PK of 'users'
//  - 'role_id' pointing on the PK of 'roles'
```

**Add a comment to a column:**

```
$table->column('description')->string(50)->comment('Lorem ipsum');
```

**Declare a primary key:**

```
$table->column('uuid')->string(36)->primaryKey();

// or

$table->column('uuid')->then()
      ->primaryKey(['uuid']);
```

**Declare an inheritance relationship between 2 tables:**

In SQL, there is no notion of "inheritance" like with PHP objects. However, a common way to model inheritance is to write one table for the base class (containing the base columns/properties) and then one table per extended class containing the additional columns/properties. Each extended table has **a primary key that is also a foreign key pointing to the base table**.

```
$db->table('contacts')
   ->id()
   ->column('email')->string(50);

$db->table('users')
   ->extends('contacts')
   ->column('password')->string(50);
```

The `extends` method will automatically create a primary key with the same name and same type as the extended table. It will also make sure this primary key is a foreign key pointing to the extended table.

Automatic 'quoting' of table and column names
---------------------------------------------

[](#automatic-quoting-of-table-and-column-names)

By default, the fluid-schema-builder will **not** quote your identifiers (because it does not know what database you use).

This means that you cannot create an item with a reserved keyword.

```
$db->table('contacts')
   ->id()
   ->column('date')->datetime(); // Will most likely fail, because "date" is a reserved keyword!
```

However, if you give to *fluid-schema-builder* your database platform at build time, then it **will quote all identifiers by default**. No more nasty surprises!

```
use TheCodingMachine\FluidSchema\DefaultNamingStrategy;

// Assuming $connection is your DBAL connection
$db = new FluidSchema($schema, new DefaultNamingStrategy($connection->getDatabasePlatform()));
```

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 73.2% 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 ~202 days

Recently: every ~279 days

Total

13

Last Release

887d ago

Major Versions

v0.1.0 → v1.0.02017-06-05

v1.7.0 → v2.0.02024-01-27

PHP version history (2 changes)v0.1.0PHP &gt;=7.1

v2.0.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1104771?v=4)[mouf](/maintainers/mouf)[@Mouf](https://github.com/Mouf)

![](https://avatars.githubusercontent.com/u/1847918?v=4)[TheCodingMachine](/maintainers/thecodingmachine)[@thecodingmachine](https://github.com/thecodingmachine)

---

Top Contributors

[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (30 commits)")[![aszenz](https://avatars.githubusercontent.com/u/25319264?v=4)](https://github.com/aszenz "aszenz (5 commits)")[![dsavina](https://avatars.githubusercontent.com/u/22031211?v=4)](https://github.com/dsavina "dsavina (4 commits)")[![homersimpsons](https://avatars.githubusercontent.com/u/16977446?v=4)](https://github.com/homersimpsons "homersimpsons (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thecodingmachine-dbal-fluid-schema-builder/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k300.5M7.5k](/packages/doctrine-orm)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M738](/packages/sylius-sylius)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M508](/packages/pimcore-pimcore)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M203](/packages/sulu-sulu)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)

PHPackages © 2026

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