PHPackages                             daursu/laravel-zero-downtime-migration - 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. daursu/laravel-zero-downtime-migration

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

daursu/laravel-zero-downtime-migration
======================================

Zero downtime migrations with Laravel and percona toolkit

2.2.0(1y ago)88884.5k↑17%14[3 issues](https://github.com/Daursu/laravel-zero-downtime-migration/issues)[2 PRs](https://github.com/Daursu/laravel-zero-downtime-migration/pulls)MITPHPPHP &gt;=8.0CI failing

Since Jul 1Pushed 3mo ago3 watchersCompare

[ Source](https://github.com/Daursu/laravel-zero-downtime-migration)[ Packagist](https://packagist.org/packages/daursu/laravel-zero-downtime-migration)[ RSS](/packages/daursu-laravel-zero-downtime-migration/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (23)Used By (0)

laravel-zero-downtime-migration
===============================

[](#laravel-zero-downtime-migration)

Zero downtime migrations with Laravel and `gh-ost` or `pt-online-schema-change`.

NOTE: works only with MySQL databases, including (Percona &amp; MariaDB).

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

[](#installation)

Compatible with Laravel `12`. For Laravel `11`, please use `v2.1.0`. For older version support, please use `v1.0`.

#### Prerequisites

[](#prerequisites)

If you are using `gh-ost` then make sure you download the binary from their releases page:

-

If you are using `pt-online-schema-change` then make sure you have `percona-toolkit` installed.

- On Mac you can install it using brew `brew install percona-toolkit`.
- On Debian/Ubuntu ` apt-get install percona-toolkit`.

#### Installation steps

[](#installation-steps)

1. Run `composer require daursu/laravel-zero-downtime-migration`
2. (Optional) Add the service provider to your `config/app.php` file, if you are not using autoloading.

```
Daursu\ZeroDowntimeMigration\ServiceProvider::class,
```

3. Update your `config/database.php` and add a new connection:

This package support `pt-online-schema-change` and `gh-ost`. Below are the configurations for each package:

###### gh-ost

[](#gh-ost)

```
'connections' => [
    'zero-downtime' => [
        'driver' => 'gh-ost',

        // This is your master write access database connection details
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),

        // Additional options, depending on your setup
        // all options available here: https://github.com/github/gh-ost/blob/master/doc/cheatsheet.md
        'params' => [
            '--max-load=Threads_running=25',
            '--critical-load=Threads_running=1000',
            '--chunk-size=1000',
            '--throttle-control-replicas=myreplica.1.com,myreplica.2.com',
            '--max-lag-millis=1500',
            '--verbose',
            '--switch-to-rbr',
            '--exact-rowcount',
            '--concurrent-rowcount',
            '--default-retries=120',
        ],
    ],
],
```

###### pt-online-schema-change

[](#pt-online-schema-change)

```
'connections' => [
    'zero-downtime' => [
        'driver' => 'pt-online-schema-change',

        // This is your master write access database connection details
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),

        // Additional options, depending on your setup
        // all options available here: https://www.percona.com/doc/percona-toolkit/LATEST/pt-online-schema-change.html
        'params' => [
            '--nocheck-replication-filters',
            '--nocheck-unique-key-change',
            '--recursion-method=none',
            '--chunk-size=2000',
        ],
    ],
],
```

Usage
-----

[](#usage)

When writing a new migration, use the helper facade `ZeroDowntimeSchema` instead of Laravel's `Schema`, and all your commands will run through `gh-ost` or `pt-online-schema-change`.

```
