orisintel/laravel-online-migrator
Run Laravel migrations online with minimal downtime. This package helps apply schema changes to large production tables without long locks, keeping your application available while migrations complete through familiar Artisan commands and safer rollouts.
This package is a niche operational tool: it helps you apply MySQL DDL through external online schema-change tooling, typically Percona Toolkit’s pt-online-schema-change, instead of issuing a blocking ALTER TABLE. It is not a general-purpose replacement for Laravel migrations. Use it only for lock-sensitive changes on large production tables.
Minimal steps:
composer.json constraints, then run the test suite or a staging migration before trusting it.pt-online-schema-change --version
composer require orisintel/laravel-online-migrator
Publish the package config using the provider/tag documented in its README. Then set the MySQL connection, binary path, and any extra CLI options. Clear config cache after changes:
php artisan config:clear
pt-online-schema-change directly. Do not assume Schema::table() is automatically intercepted.First useful case: adding a composite index to a large orders table without a long metadata lock.
ALTER TABLE orders
ADD INDEX orders_customer_created_idx (customer_id, created_at);
Use the package’s documented online migration entry point to apply that DDL. If the package does not expose a dry-run, run the equivalent pt-online-schema-change --dry-run --print command manually first and compare it with what the package generates.
Where to look first:
config/ for connection, binary path, and extra arguments.src/Console/Commands and the service provider for the actual execution path.composer.json for Laravel, PHP, and dependency constraints.Separate online migrations from normal migrations. Keep lock-sensitive changes in a dedicated directory, namespace, or command path so they are run deliberately, not accidentally during every local php artisan migrate. Normal Laravel migrations remain fine for small tables, new tables, seed data, and non-production work.
Use a deployment gate. Run online schema changes as an explicit CI/CD or pre-deploy step, then deploy application code. If the package integrates with php artisan migrate, gate it by environment flag so local and test environments do not try to invoke Percona Toolkit.
# Example pipeline shape, not necessarily exact package commands
php artisan migrate:online --force # or package-specific command
php artisan migrate --force
Confirm whether the package records applied migrations in Laravel’s migrations table. If it does not, add a normal no-op migration or manually record state so the same online change is not replayed.
Keep each online change small and reversible. Prefer one index or one column change per migration. pt-online-schema-change can handle multiple clauses in one ALTER, but smaller changes are easier to throttle, observe, and roll back.
Configure conservative production options. Use package config or extra CLI args to limit load:
// Example shape only; verify keys against the published config.
return [
'connection' => env('ONLINE_MIGRATOR_CONNECTION', 'mysql'),
'binary' => env('PT_OSC_BINARY', 'pt-online-schema-change'),
'options' => [
'--chunk-time' => '0.5',
'--max-load' => 'Threads_running=30',
'--critical-load' => 'Threads_running=60',
'--sleep' => '0.1',
],
];
Use faster settings in staging; use throttling, replication-lag checks, and off-peak windows in production.
Add observability around the command. Capture start/end time, exit code, stdout/stderr, target table, generated DDL, and migration name. Monitor MySQL SHOW PROCESSLIST, replication lag, disk space, and InnoDB metrics while it runs. A successful package command without logs is not enough for production confidence.
Run sequentially per database server. Do not parallelize online migrations on the same MySQL instance. For multi-tenant or sharded databases, loop over connections one at a time with backoff between runs.
Have a fallback plan. If the package is incompatible with your Laravel version or lacks needed hooks, wrap pt-online-schema-change in your own Artisan command and keep the package only as reference. This is often safer than fighting an unmaintained integration layer.
pt-online-schema-change creates a ghost table, installs triggers, copies rows, and doubles write load during the run. It can cause replication lag, disk pressure, and trigger conflicts. Take a backup or snapshot first.pt-online-schema-change limits. The table generally needs a primary key or unique index. Existing triggers can conflict unless --preserve-triggers is supported and used. Foreign keys may require --alter-foreign-keys-method. Table-name length limits can also bite because of generated ghost-table names.ALTER TABLE SQL. Laravel’s schema builder can generate SQL that the external tool handles poorly. Test the exact generated DDL in staging, including table prefixes and quoted identifiers.max_execution_time, CI job timeouts, queue worker timeouts, and deploy timeouts can kill a long-running online migration. Run it from CLI with appropriate timeouts, not from a web request.php artisan config:clear. Verify the binary is on PATH or provide an absolute path.pt-online-schema-change --dry-run --print where possible. Then inspect SHOW TRIGGERS, SHOW PROCESSLIST, replication status, and leftover ghost/old tables.down() online migration is another online DDL operation, and the package may not handle it safely. Know the reverse ALTER and test it on staging.How can I help you explore Laravel packages today?