PHP

Doctrine Migrations migrations, drawn as a database diagram

Version classes with up() and down(), as generated by Symfony's doctrine:migrations commands. SchemaDrawer runs doctrine/migrations 3.9.7 with Doctrine DBAL 4.4 on PHP 8.4 against a throw-away database of the engine you choose and returns an SVG of the schema it produces.

What to upload

Upload the Version*.php classes, at any depth. Every file must declare its namespace with a namespace Name; statement; each namespace found is mapped to the upload directory in the generated configuration.

The sample below is the PetClinic schema written for Doctrine Migrations, one of the sets SchemaDrawer's own tests draw on every engine:

migrations/
├── Version20240101000001.php
├── Version20240101000002.php
└── Version20240101000003.php

Formats

PHP migration classes extending AbstractMigration.

How it runs

doctrine-migrations migrate --no-interaction with a configuration generated for the drawing. The database is a fresh PostgreSQL, MySQL, MariaDB, SQL Server, Oracle or SQLite container in the version you ask for; nothing of yours is touched.

Databases you can draw Doctrine Migrations on

PostgreSQL 10, 11, 12, 13, 14, 15, 16, 17, 18 MySQL 8.0, 8.4, 9 MariaDB 10.6, 11.4, 11.8, 12 SQL Server 2017, 2019, 2022, 2025 Oracle 21, 23 SQLite

At a glance

Runs
doctrine/migrations 3.9.7 with Doctrine DBAL 4.4 on PHP 8.4
API value
migrationType=DOCTRINE
Engines
6 of 6: PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite
Output
SVG diagram with tables, columns and types, primary and foreign keys
Price
Free today; enterprise plans are coming
Example

The PetClinic schema in Doctrine Migrations

Owners, pets, types, vets, specialties and visits: the same seven tables every sample set on this site creates. These are the exact files the tests upload.

<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240101000001 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'create owners and pets';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            CREATE TABLE owners
            (
                id         INT          NOT NULL,
                first_name VARCHAR(50)  NOT NULL,
                last_name  VARCHAR(50)  NOT NULL,
                address    VARCHAR(255),
                city       VARCHAR(80),
                telephone  VARCHAR(20),
                CONSTRAINT pk_owners PRIMARY KEY (id)
            )
            SQL);
        $this->addSql(<<<'SQL'
            CREATE TABLE types
            (
                id   INT         NOT NULL,
                name VARCHAR(80) NOT NULL,
                CONSTRAINT pk_types PRIMARY KEY (id)
            )
            SQL);
        $this->addSql(<<<'SQL'
            CREATE TABLE pets
            (
                id         INT         NOT NULL,
                name       VARCHAR(50) NOT NULL,
                birth_date DATE,
                type_id    INT         NOT NULL,
                owner_id   INT         NOT NULL,
                CONSTRAINT pk_pets PRIMARY KEY (id),
                CONSTRAINT fk_pets_types FOREIGN KEY (type_id) REFERENCES types (id),
                CONSTRAINT fk_pets_owners FOREIGN KEY (owner_id) REFERENCES owners (id)
            )
            SQL);
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP TABLE pets');
        $this->addSql('DROP TABLE types');
        $this->addSql('DROP TABLE owners');
    }
}
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240101000002 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'create vets';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            CREATE TABLE vets
            (
                id         INT         NOT NULL,
                first_name VARCHAR(50) NOT NULL,
                last_name  VARCHAR(50) NOT NULL,
                CONSTRAINT pk_vets PRIMARY KEY (id)
            )
            SQL);
        $this->addSql(<<<'SQL'
            CREATE TABLE specialties
            (
                id   INT         NOT NULL,
                name VARCHAR(80) NOT NULL,
                CONSTRAINT pk_specialties PRIMARY KEY (id)
            )
            SQL);
        $this->addSql(<<<'SQL'
            CREATE TABLE vet_specialties
            (
                vet_id       INT NOT NULL,
                specialty_id INT NOT NULL,
                CONSTRAINT pk_vet_specialties PRIMARY KEY (vet_id, specialty_id),
                CONSTRAINT fk_vet_specialties_vets FOREIGN KEY (vet_id) REFERENCES vets (id),
                CONSTRAINT fk_vet_specialties_specialties FOREIGN KEY (specialty_id) REFERENCES specialties (id)
            )
            SQL);
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP TABLE vet_specialties');
        $this->addSql('DROP TABLE specialties');
        $this->addSql('DROP TABLE vets');
    }
}
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240101000003 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'create visits';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            CREATE TABLE visits
            (
                id          INT NOT NULL,
                pet_id      INT NOT NULL,
                visit_date  DATE,
                description VARCHAR(255),
                CONSTRAINT pk_visits PRIMARY KEY (id),
                CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id)
            )
            SQL);
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP TABLE visits');
    }
}
diagram.svg
ER diagram of the PetClinic schema drawn by SchemaDrawer: owners, pets, types, vets, specialties, vet_specialties and visits with their columns, primary keys and foreign keys

Every variant of the sample produces these seven tables. This diagram was drawn from the Flyway variant on PostgreSQL 18; on MySQL the types read INT and VARCHAR, on Oracle the names are upper case.

Run it

Draw your Doctrine Migrations migrations

One multipart request queues the drawing; poll the job until it succeeds and download the SVG. Or let the GitHub Action do it and open a pull request with the diagram.

With curl

curl -X POST https://schemadrawer.com/api/v1/drawing \
  -H "Request-Id: $(uuidgen)" \
  -F "userId=5f0c1d2e-3a4b-4c5d-8e6f-7a8b9c0d1e2f" \
  -F "migrationType=DOCTRINE" \
  -F "databaseType=POSTGRESQL" \
  -F "version=18" \
  -F "files=@migrations/Version20240101000001.php" \
  -F "files=@migrations/Version20240101000002.php" \
  -F "files=@migrations/Version20240101000003.php"
# {"jobId":"0b6e2f4c-8d1a-4c3e-9f7a-2a5b6c7d8e9f"}

Then poll GET https://schemadrawer.com/api/v1/drawing/{jobId} until status is SUCCESS and fetch diagramUrl. Details in the getting started guide and the API reference.

With the GitHub Action

- uses: schemadrawercom/action@v1
  with:
    sql-directory: migrations
    output-path: docs/schema-diagram.svg
    migration-type: DOCTRINE
    database-type: POSTGRESQL
    database-version: '18'
    github-token: ${{ secrets.GITHUB_TOKEN }}

The action uploads the directory, waits for the diagram and opens a pull request with the SVG. See the action reference.

Good to know

  • Your own migrations configuration is not used, and an upload without a PHP file or without a namespace declaration is refused before anything runs.
  • The doctrine_migration_versions table is left out of the diagram.
  • A drawing may take up to 120 seconds; a job that waits in the queue longer than 10 minutes fails rather than draws. Uploads of up to 100 MB and 2000 files are accepted.
From the blog

Reading about Doctrine Migrations and migrations

Draw your Doctrine Migrations schema now

Upload the migration directory, get an SVG back. Free while we build it.