PHPackages                             graze/morphism - 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. graze/morphism

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

graze/morphism
==============

MySQL Database Migration

v7.1.0(1mo ago)63.5k[3 issues](https://github.com/graze/morphism/issues)MITPHPPHP ^7.4 || ^8.0CI passing

Since Jan 29Pushed 1mo ago15 watchersCompare

[ Source](https://github.com/graze/morphism)[ Packagist](https://packagist.org/packages/graze/morphism)[ Docs](https://github.com/graze/morphism)[ RSS](/packages/graze-morphism/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (24)Versions (35)Used By (0)

morphism
========

[](#morphism)

[![Latest Version on Packagist](https://camo.githubusercontent.com/476e6b656d9761ce77b46cba9ca8f94586ec2f364fd4b79666db045133edf92e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772617a652f6d6f72706869736d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graze/morphism)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/d198f3ef6f0d36f98a88fc9e1b8bd8cb2cc9c84cddc672e9c9aeebea9232bcd9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6772617a652f6d6f72706869736d2f63692e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/graze/morphism/actions/workflows/ci.yml)[![Total Downloads](https://camo.githubusercontent.com/d3c49d729bf91f8bc41e8241589c504d0ee3c0bcdaf3292772a02c5174177417/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772617a652f6d6f72706869736d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graze/morphism)[![PHP Version](https://camo.githubusercontent.com/db310ecac027d0511fa3ac91fc552a8e303d3667c7ed9b24d4b59b4286368cd8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6772617a652f6d6f72706869736d2e7376673f7374796c653d666c61742d737175617265)](https://php.net)

This package provides a set of tools for parsing, extracting, and diffing mysqldump files.

A typical application of this is for managing schema changes during application development (keeping schemas in sync with code when switching branches), and during deployment (migrating the schema to match the deployed code).

Using this tool allows you to store the complete database schema in the repository. When a branch requires a schema update to work properly, you should edit your checkout's schema and run the new tool to figure out the necessary `ALTER` / `CREATE` / `DROP` statements to run, and apply them. Similarly, when switching branches you can simply run the tool and it will apply the necessary changes automatically.

This has the additional benefit that the complete history of the schema is stored under version control, instead of a series of incremental change scripts. If more than one party changes the same table, git will merge the changes automatically, or generate a conflict for manual merging where it cannot. All the usual git tools become useful - e.g. a simple `git annotate schema/catalog/product.sql` can tell you who added a redundant index on `pr_name`.

Install
-------

[](#install)

Via Composer

```
$ composer require graze/morphism
```

Running With Docker
-------------------

[](#running-with-docker)

```
$ docker run --rm graze/morphism
```

### Examples:

[](#examples)

```
$ docker run --rm -v $PWD/config:/app/config -v $PWD/schema:/app/schema:cached graze/morphism diff config/morphism.yml
$ docker run --rm -v $PWD/config:/app/config -v $PWD/schema:/app/schema:delegated graze/morphism dump config/morphism.yml
```

### Attaching to an existing network when developing

[](#attaching-to-an-existing-network-when-developing)

You can add morphism to your `docker-compose` file and can talk to your databases locally. Or if you have an existing docker network you can do:

```
$ docker run --rm -v $PWD/config:/app/config -v $PWD/schema:/app/schema:cached --network app_default graze/morphsim diff config/morphism.yml
```

Tools
-----

[](#tools)

All commands support the `--help` parameter which give more information on usage.

- **morphism extract**: Extract schema definitions from a mysqldump file.
- **morphism dump**: Dump database schema for a named database connection.
- **morphism lint**: Check database schema files for correctness.
- **morphism diff**: Show necessary DDL statements to make a given database match the schema files. Optionally apply the changes too.

Config File
-----------

[](#config-file)

The config file used by some of morphism's tools uses yaml format, as follows:

```
# All connection definitions appear under the 'databases' key
databases:
    # name of connection
    catalog:
        # Connection details - this is just an example, you may want to specify
        # different properties, e.g. if connecting to a remote server. You are
        # advised to refer to the 'pdo' documentation for further details.
        user: 'my-user'
        password: 'my-password'
        host: 'localhost'
        driver: 'pdo_mysql'
        unix_socket: '/var/lib/mysql/catalog.sock'
        # morphism specific options
        morphism:
            # morphism diff only operates on connections with 'enable: true'
            enable: true
            # Path where schema files live.
            # Defaults to "schema/"
            schemaDefinitionPath:
                - schema/catalog
            # you may optionally specify one or more regexes matching tables
            # to exclude (any changes, creation or deletion of matching tables
            # will be ignored). The regex must match the entire table name, i.e.
            # it is implicitly anchored with ^...$
            exclude:
                - temp_.*
                - page_load_\d{4}-\d{2}-\d{2}
            # similarly, you may optionally specify tables for explicit inclusion.
            include:
                ...
    # you may specify more connections
    ...
# other top level keys are ignored
...

```

Example Usage
-------------

[](#example-usage)

This example uses `morphism dump` to generate schema files from a database, `morphism lint` for checking the files and `morphism diff` to apply changes both interactively and automatically.

```
(master) $ # create a baseline for the schema
(master) $ mkdir schema
(master) $ bin/morphism dump --write config.yml catalog
(master) $ git add schema/catalog
(master) $ git commit -m "initial checkin of catalog schema"
(master) $
(master) $ # start work on changes to the catalog...
(master) $ git checkout -b catalog-fixes
(catalog-fixes) $ vi schema/catalog/product.sql             # edit table definition
(catalog-fixes) $ vi schema/catalog/product_dimensions.sql  # add new table
(catalog-fixes) $ bin/morphism lint schema/catalog   # check syntax
ERROR schema/catalog/product_dimensions.sql, line 2: unknown datatype 'intt'
1: CREATE TABLE product_dimensions (
2:   `pd_id` intt(10) unsigned NOT NULL AUTO_INCREMENT,
(catalog-fixes) $ vi schema/catalog/product_dimensions.sql  # fix table definition
(catalog-fixes) $ bin/morphism lint schema/catalog   # check syntax
(catalog-fixes) $ git add schema/catalog
(catalog-fixes) $ git rm schema/catalog/discontinued.sql    # delete a table
(catalog-fixes) $ git commit -m "various changes to catalog schema"
(catalog-fixes) $ # alter the database to match the schema files
(catalog-fixes) $ bin/morphism diff --apply-changes=confirm config.yml catalog
-- --------------------------------
--   Connection: catalog
-- --------------------------------
DROP TABLE IF EXISTS `discontinued`;

ALTER TABLE `product`
MODIFY COLUMN `pr_name` varchar(255) NOT NULL,
MODIFY COLUMN `pr_description` text NOT NULL,
ADD COLUMN `pr_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `pr_description`;

CREATE TABLE `product_dimensions` (
  `pd_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `pd_width` decimal(10,2) NOT NULL,
  `pd_height` decimal(10,2) NOT NULL,
  `pd_depth` decimal(10,2) NOT NULL,
  PRIMARY KEY (`pd_id`)
) ENGINE=InnoDB;

-- Confirm changes to catalog:

DROP TABLE IF EXISTS `discontinued`;

-- Apply this change? [y]es [n]o [a]ll [q]uit: y

ALTER TABLE `product`
MODIFY COLUMN `pr_name` varchar(255) NOT NULL,
MODIFY COLUMN `pr_description` text NOT NULL,
ADD COLUMN `pr_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `pr_description`;

-- Apply this change? [y]es [n]o [a]ll [q]uit: y

CREATE TABLE `product_dimensions` (
  `pd_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `pd_width` decimal(10,2) NOT NULL,
  `pd_height` decimal(10,2) NOT NULL,
  `pd_depth` decimal(10,2) NOT NULL,
  PRIMARY KEY (`pd_id`)
) ENGINE=InnoDB;

-- Apply this change? [y]es [n]o [a]ll [q]uit: y
(catalog-fixes) $ # hack hack hack
(catalog-fixes) $ ...
(catalog-fixes) $ # do some work back on master...
(catalog-fixes) $ git checkout master
(master) $ # restore schema to previous state
(master) $ bin/morphism diff --apply-changes=yes config.yml catalog

```

Testing
-------

[](#testing)

```
$ make test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance83

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~165 days

Recently: every ~189 days

Total

26

Last Release

34d ago

Major Versions

v2.3.0 → v3.0.02018-06-10

v3.0.1 → v4.0.02018-07-20

v4.1.1 → v5.0.02019-02-15

v5.1.0 → v6.0.02020-02-26

v6.0.5 → v7.0.02026-05-27

PHP version history (7 changes)1.1.4PHP &gt;=5.4

2.0.x-devPHP &gt;=5.5

v4.0.0PHP ^5.6 | ^7.0

v5.0.1PHP ^7.1

v6.0.0PHP ^7.2

v7.0.0PHP ^7.4

v7.1.0PHP ^7.4 || ^8.0

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/7c157a7289b7177389ddbcb5509f17255891d7084a60d9a8adbff7df7a2953a1?d=identicon)[biggianteye](/maintainers/biggianteye)

---

Top Contributors

[![biggianteye](https://avatars.githubusercontent.com/u/1482649?v=4)](https://github.com/biggianteye "biggianteye (78 commits)")[![adrmcintyre](https://avatars.githubusercontent.com/u/2235385?v=4)](https://github.com/adrmcintyre "adrmcintyre (51 commits)")[![rick-lam](https://avatars.githubusercontent.com/u/114425681?v=4)](https://github.com/rick-lam "rick-lam (28 commits)")[![john-n-smith](https://avatars.githubusercontent.com/u/1314694?v=4)](https://github.com/john-n-smith "john-n-smith (8 commits)")[![brendankay](https://avatars.githubusercontent.com/u/641490?v=4)](https://github.com/brendankay "brendankay (7 commits)")[![wpillar](https://avatars.githubusercontent.com/u/188514?v=4)](https://github.com/wpillar "wpillar (4 commits)")[![joemeehan](https://avatars.githubusercontent.com/u/2518301?v=4)](https://github.com/joemeehan "joemeehan (2 commits)")[![RokasDevelopment](https://avatars.githubusercontent.com/u/13278000?v=4)](https://github.com/RokasDevelopment "RokasDevelopment (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

databasemysqlmysqldumpphpmigrationdatabasemysqlmigrate

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/graze-morphism/health.svg)

```
[![Health](https://phpackages.com/badges/graze-morphism/health.svg)](https://phpackages.com/packages/graze-morphism)
```

###  Alternatives

[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M552](/packages/shopware-core)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[sulu/sulu

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

1.3k1.4M198](/packages/sulu-sulu)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103519.9k48](/packages/friendsoftypo3-content-blocks)[open-dxp/opendxp

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

9421.6k59](/packages/open-dxp-opendxp)[contao/core-bundle

Contao Open Source CMS

1231.6M2.7k](/packages/contao-core-bundle)

PHPackages © 2026

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