erjanmx/laravel-migrate-check
Installation:
composer require erjanmx/laravel-migrate-check
No additional configuration is needed due to Laravel’s package auto-discovery.
First Use Case: Integrate into a CI/CD pipeline or deployment script to verify pending migrations before proceeding. Example:
php artisan migrate:check --exit-code
0 (success) if no pending migrations.1 (failure) if migrations are pending.Where to Look First:
CI/CD Integration:
# Example GitHub Actions step
- name: Check for pending migrations
run: php artisan migrate:check --exit-code || exit 1
migrate in a single step:
php artisan migrate:check --exit-code && php artisan migrate --force
Automated Maintenance Mode:
// In a deployment script
$exitCode = Artisan::call('migrate:check --exit-code');
if ($exitCode !== 0) {
throw new \RuntimeException('Pending migrations detected!');
}
Artisan::call('down');
Custom Database Support:
php artisan migrate:check --database=secondary_db
Silent Mode:
php artisan migrate:check --quiet
migrate:check in a pre-flight script to ensure no migrations are pending before switching traffic.php artisan migrate:check --exit-code || php artisan migrate:fresh
entrypoint.sh to fail fast if migrations are pending:
if ! php artisan migrate:check --exit-code; then
echo "Migrations pending! Exiting."
exit 1
fi
$this->artisan('migrate:check')
->expectsQuestion('Continue?', 'no')
->assertExitCode(1);
Exit Code Misuse:
--exit-code will always return 0, even with pending migrations.--exit-code in scripts.Database Connection Issues:
.env is misconfigured, it may fail silently.php artisan migrate:check --database=mysql
Race Conditions:
migrate:check and migrate.php artisan migrate --force --pretend first).Custom Migration Paths:
config/database.php correctly.--path to override:
php artisan migrate:check --path=database/migrations/custom
--verbose to debug connection/migration issues:
php artisan migrate:check --verbose
php artisan migrate:check --pretend
Environment-Specific Behavior:
APP_ENV (e.g., testing environment may behave differently).APP_ENV=staging.No Configuration File:
Custom Logic:
php artisan vendor:publish --tag=migrate-check
app/Console/Commands/MigrateCheckCommand.php.Event Listeners:
// In EventServiceProvider
protected $listen = [
'migrate.check.failed' => [YourAlertHandler::class],
];
Integration with Laravel Packages:
spatie/laravel-backup to skip backups if migrations are pending:
if (Artisan::call('migrate:check --exit-code') !== 0) {
Backup::withoutMigrations();
}
How can I help you explore Laravel packages today?