All Projects → orisintel → laravel-online-migrator

orisintel / laravel-online-migrator

Licence: MIT License
Apply Laravel's database migrations with minimal disruptions using tools like Percona Online Schema Change

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-online-migrator

gitlab to gitea
Gitlab to Gitea migration script.
Stars: ✭ 54 (+25.58%)
Mutual labels:  migration
fastfreeze
Turn-key solution to checkpoint/restore applications running in Linux containers
Stars: ✭ 68 (+58.14%)
Mutual labels:  migration
email-checker
Provides email verification on the go.
Stars: ✭ 116 (+169.77%)
Mutual labels:  laravel-framework
Squeaky-Android
Appropriately lightweight database creations and migrations with SQLite on Android
Stars: ✭ 34 (-20.93%)
Mutual labels:  migration
trona
Write DB migrations with SQL and run them with a CLI
Stars: ✭ 31 (-27.91%)
Mutual labels:  migration
artisan-shortcuts
🍰 Register shortcuts to execute multiple artisan commands
Stars: ✭ 56 (+30.23%)
Mutual labels:  laravel-framework
laravel-crm
Free & Opensource Laravel CRM solution for SMEs and Enterprises for complete customer lifecycle management.
Stars: ✭ 927 (+2055.81%)
Mutual labels:  laravel-framework
loopback-component-migrate
Migration framework for loopback
Stars: ✭ 43 (+0%)
Mutual labels:  migration
laravel-qr-code-login
Today I will be showing you how to implement Laravel login with QRcode in a website. You can use my Laravel Starter so you can start the project in one minute .
Stars: ✭ 72 (+67.44%)
Mutual labels:  laravel-framework
mammaskitchen
A Simple Restaurant Management
Stars: ✭ 72 (+67.44%)
Mutual labels:  laravel-framework
maildir2gmail
Maildir 2 Gmail
Stars: ✭ 14 (-67.44%)
Mutual labels:  migration
rails async migrations
Asynchronous support for ActiveRecord::Migration
Stars: ✭ 56 (+30.23%)
Mutual labels:  migration
teamo-ddd-example
Implementing Domain Driven Design in PHP using Laravel
Stars: ✭ 46 (+6.98%)
Mutual labels:  laravel-framework
clubi
A group-oriented social media platform written in Laravel and Vue
Stars: ✭ 29 (-32.56%)
Mutual labels:  laravel-framework
ocp-flyway-db-migration
Database Migration Sample with Flyway, Docker and Kubernetes in Openshift Container Platform
Stars: ✭ 17 (-60.47%)
Mutual labels:  migration
LaraShop
Simple PHP shop CMS based on Laravel 5.1
Stars: ✭ 73 (+69.77%)
Mutual labels:  laravel-framework
jikkyo-api
ニコニコ実況 過去ログ API(非公式)
Stars: ✭ 17 (-60.47%)
Mutual labels:  laravel-framework
plow
👨‍🌾 Postgres migrations and seeding made easy
Stars: ✭ 13 (-69.77%)
Mutual labels:  migration
illuminate
Yii2 to Laravel Migration Package
Stars: ✭ 71 (+65.12%)
Mutual labels:  migration
crater
Open Source Invoicing Solution for Individuals & Businesses
Stars: ✭ 5,938 (+13709.3%)
Mutual labels:  laravel-framework

Laravel Online Migrator

Latest Version on Packagist Build Status Total Downloads

This package minimizes disruptions when applying Laravel's database migrations using tools like Percona Online Schema Change or InnoDB Online DDL. For example, one can write (mostly) standard Laravel migration files then run "php artisan migrate". Database changes will be automatically converted into PTOSC commands or online DDL queries.

Installation

You can install the package via composer:

composer require orisintel/laravel-online-migrator

The pt-online-schema-change command from Percona's toolkit must be in the path where Artisan will be run, unless InnoDB Online DDL is being used exclusively.

Configuration

Publish the configuration file:

php artisan vendor:publish --provider='OrisIntel\OnlineMigrator\OnlineMigratorServiceProvider'

If not using discovery then add the provider to config/app.php:

'providers' => [
    // ...
    OrisIntel\OnlineMigrator\OnlineMigratorServiceProvider::class,

If changing tables with enum columns consider working around "Unknown database type enum requested" by tweaking config/online-migrator.php:

  'doctrine-enum-mapping' => env('DOCTRINE_ENUM_MAPPING', 'string'),

or .env with DOCTRINE_ENUM_MAPPING=string

Usage

Run Artisan's migrate to apply migrations online*:

php artisan migrate

*Limitations are documented below.

Preview what changes it would make:

php artisan migrate --pretend

Add PTOSC options using environment variables:

PTOSC_OPTIONS='--recursion-method=none'  php artisan migrate

Flag migrations known to be incompatible with this tool using the built-in trait:

class MyMigration extends Migration
{
    use \OrisIntel\OnlineMigrator\OnlineIncompatible

Use a different strategy for a single migration:

class MyMigration extends Migration
{
    use \OrisIntel\OnlineMigrator\InnodbOnlineDdl

Do not combine queries for a migration when using PTOSC:

class MyMigration extends Migration
{
    use \OrisIntel\OnlineMigrator\CombineIncompatible

Adding foreign key with index to existing table:

class MyColumnWithFkMigration extends Migration
{
    public function up()
    {
        Schema::table('my_table', function ($table) {
            $table->integer('my_fk_id')->index();
        });

        Schema::table('my_table', function ($table) {
            $table->foreign('my_fk_id')->references('id')->on('my_table2');

Limitations

  • Only supports Mysql, specifically those versions supported by PTOSC v3
  • With PTOSC
    • Adding unique indexes may cause data loss unless tables are manually checked beforehand because of how PTOSC works
    • Adding not-null columns requires a default
    • Renaming a column or dropping a primary key have additional risks
    • Foreign key creation should be done separately from column creation or duplicate indexes may be created with slightly different naming
      • Close the Schema::create() call and make a separate Schema::table() call for all FKs in the migration
  • With InnoDB Online DDL
  • Stateful migrations, like those selecting then saving rows, will instead need to do one of the following:
    • Use non-selecting queries like MyModel::where(...)->update(...)
    • Pipe the raw SQL like \DB::statement('UPDATE ... SET ... WHERE ...');
    • Use the OnlineMigratorIncompatible trait to mark the migration as incompatible

Testing

composer test

Output is verbose because passthru is used to help debug production problems. Executing as phpunit --testdox may be more readable until the verbosity can be tamed.

Contributing

Please see CONTRIBUTING for details.

Security

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

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].