PHPackages                             phlib/schema-change - 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. phlib/schema-change

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

phlib/schema-change
===================

Library for performing MySQL DDL operations, using either simple SQL or Percona Tools Online Schema Change

1.1.0(1y ago)348.0k↓32.4%2LGPL-3.0PHPPHP ^8.1CI failing

Since Sep 2Pushed 1y ago2 watchersCompare

[ Source](https://github.com/phlib/schema-change)[ Packagist](https://packagist.org/packages/phlib/schema-change)[ RSS](/packages/phlib-schema-change/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

phlib/schema-change
===================

[](#phlibschema-change)

[![Code Checks](https://camo.githubusercontent.com/23a9e9f4fc35f4de165112a059e64c8c8cc6ebd80a7d93fbf0529a821539599d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70686c69622f736368656d612d6368616e67652f636f64652d636865636b732e796d6c3f6c6f676f3d676974687562)](https://github.com/phlib/schema-change/actions/workflows/code-checks.yml)[![Codecov](https://camo.githubusercontent.com/b16635062de44d6e6da49cf5bdf944f495b6ff3e7bcc9ba5af4631b117a2c16c/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f70686c69622f736368656d612d6368616e67652e7376673f6c6f676f3d636f6465636f76)](https://codecov.io/gh/phlib/schema-change)[![Latest Stable Version](https://camo.githubusercontent.com/a3343ba7b83b636f7718507d89d24dabcae3ea8c8f8bceb899b2407374879739/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70686c69622f736368656d612d6368616e67652e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/schema-change)[![Total Downloads](https://camo.githubusercontent.com/bc7bc46b339f99e276d6a468cc3c718434fcaac80ea56ae44cd508c093fa1dd9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70686c69622f736368656d612d6368616e67652e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/schema-change)[![Licence](https://camo.githubusercontent.com/e5808e1a88c0364f329f0f319d6d8221120b2909aa3ac831fdffacb64eeeb318/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f736368656d612d6368616e67652e737667)](https://camo.githubusercontent.com/e5808e1a88c0364f329f0f319d6d8221120b2909aa3ac831fdffacb64eeeb318/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f736368656d612d6368616e67652e737667)

Library for performing MySQL DDL operations, using either simple SQL or Percona Tools Online Schema Change.

This library is designed to be able to be used in any existing migrations management tool.

Usage
-----

[](#usage)

### Setup

[](#setup)

```
$db = new Phlib\Db\Adapter([
    'host' => '127.0.0.1',
    'port' => '3306',
    'username' => 'root',
    'password' => '',
    'dbname' => 'base_schema',
]);

$schemaChange = new \Phlib\SchemaChange\SchemaChange(
    $db,
    new \Phlib\SchemaChange\OnlineChangeRunner('/usr/local/bin/pt-online-schema-change')
);

$schemaChange->mapNames(new class implements \Phlib\SchemaChange\NameMapper {
    public function mapTableName(string $table): string
    {
        return 'prefix_' . $table;
    }
});
```

### Create a table

[](#create-a-table)

```
$create = $schemaChange->create('widget');

$create->addColumn('id', 'int(11)')->unsigned()->notNull()->autoIncrement();
$create->addColumn('folder_id', 'int(11)')->notNull();
$create->addColumn('name', 'varchar(255)')->notNull();
$create->addColumn('data', 'text')->notNull()->defaultTo('');
$create->addColumn('create_ts', 'timestamp')->notNull()->defaultRaw('CURRENT_TIMESTAMP')

$create->primary('id');
$create->addIndex('folder_id', 'name')->unique();
$create->attribute('DEFAULT CHARSET', 'ascii');

$schemaChange->execute($create);
```

### Alter a table

[](#alter-a-table)

```
$alter = $schemaChange->alter('widget')
    ->onlineChange();

$alter->removeColumn('data');
$alter->addColumn('alias', 'varchar(100)')->nullable()->after('name');
$alter->addColumn('update_ts', 'timestamp')->after('create_ts')->notNull()
    ->defaultRaw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');

$alter->removeIndex('widget_folder_id_name_idx');

$schemaChange->execute($alter);
```

### Drop a table

[](#drop-a-table)

```
$drop = $schemaChange->drop('widget');
$schemaChange->execute($drop);
```

License
-------

[](#license)

This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see .

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance40

Moderate activity, may be stable

Popularity34

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 95.1% 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 ~662 days

Total

4

Last Release

507d ago

Major Versions

0.0.1 → 1.0.02022-09-14

PHP version history (3 changes)0.0.1PHP ^7.1

1.0.0PHP ^7.4 || ^8.0

1.1.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/10c53cdcfb3a6d299820aecb993521cc1a972baa09fd8f31d2468908cded7e1d?d=identicon)[chrisminett](/maintainers/chrisminett)

---

Top Contributors

[![chrisminett](https://avatars.githubusercontent.com/u/1084019?v=4)](https://github.com/chrisminett "chrisminett (39 commits)")[![awhale](https://avatars.githubusercontent.com/u/6044970?v=4)](https://github.com/awhale "awhale (2 commits)")

###  Code Quality

TestsPHPUnit

Code StyleECS

### Embed Badge

![Health badge](/badges/phlib-schema-change/health.svg)

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

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[spatie/db-dumper

Dump databases

1.2k29.1M86](/packages/spatie-db-dumper)[getgrav/grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS

15.6k86.4k1](/packages/getgrav-grav)[kimai/kimai

Kimai - Time Tracking

4.8k9.0k1](/packages/kimai-kimai)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136406.3k14](/packages/rector-rector-src)

PHPackages © 2026

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