Download the PHP package daursu/laravel-zero-downtime-migration without Composer
On this page you can find all versions of the php package daursu/laravel-zero-downtime-migration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download daursu/laravel-zero-downtime-migration
More information about daursu/laravel-zero-downtime-migration
Files in daursu/laravel-zero-downtime-migration
Package laravel-zero-downtime-migration
Short Description Zero downtime migrations with Laravel and percona toolkit
License MIT
Informations about the package 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 & MariaDB).
Installation
Compatible with Laravel 8.0
, 9.0
& 10.0
. For older version support, please use v1.0
.
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
- Run
composer require daursu/laravel-zero-downtime-migration
-
(Optional) Add the service provider to your
config/app.php
file, if you are not using autoloading. - 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
pt-online-schema-change
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
.
Run php artisan:migrate
Configuration
All the configuration is done inside config/database.php
on the connection itself.
You can pass down custom flags to the raw pt-online-schema-change
command.
Simply add the parameters you want inside the params
array like so:
You can find all the possible options here: https://www.percona.com/doc/percona-toolkit/LATEST/pt-online-schema-change.html
Tests
The ZeroDowntimeSchema
facades allows you disable running pt-online-schema-change
during tests.
To do so, in your base test case TestCase.php
under the setUp method add the following:
This will disable pt-online-schema-change
and all the migrations using the helper facade will run
through the default laravel migrator.
Custom connection name
By default, the connection name used by ZeroDowntimeSchema
helper is set to zero-downtime
, however you can
override this if you called your connection something else in config/database.php
.
To do so, in your AppServiceProvider.php
add the following under the boot()
method:
Replication
If your database is running in a cluster with replication, then you need to
configure how pt-online-schema-changes
finds your replica slaves.
Here's an example setup, but feel free to customize it to your own needs
- Replace
database_name
with your database name. -
Create a new table called
dsns
- Add a new row for each replica you have, example
Upgrade to v1
There is one breaking change introduced in v1, that requires to modify
the configuration in database.php
. The additional parameters array passed down to
pt-online-schema-change
or gh-ost
has been renamed from options
to params
.
This change was required as the name options
conflicts with Laravel's database configuration
that is automatically passed down to PDO.
Gotchas
- This only works with MySQL, Percona & MariaDB
- Use this tool when you need to alter a table, not when creating or dropping tables.
All versions of laravel-zero-downtime-migration with dependencies
illuminate/database Version ^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
symfony/console Version ^5.0|^6.0|^7.0
symfony/process Version ^5.0|^6.0|^7.0