2026-06-15 14:59:52 +03:30
|
|
|
<?php
|
|
|
|
|
|
2026-06-15 15:06:34 +03:30
|
|
|
namespace App\Console;
|
2026-06-15 14:59:52 +03:30
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Events\Dispatcher;
|
|
|
|
|
use Illuminate\Database\Console\Migrations\MigrateCommand as BaseMigrateCommand;
|
|
|
|
|
use Illuminate\Database\Migrations\Migrator;
|
|
|
|
|
|
2026-06-15 15:06:34 +03:30
|
|
|
/**
|
|
|
|
|
* فقط از طریق AppServiceProvider روی command.migrate ثبت میشود —
|
|
|
|
|
* داخل Commands/ نباشد تا Kernel آن را auto-load نکند.
|
|
|
|
|
*/
|
2026-06-15 14:59:52 +03:30
|
|
|
class MigrateCommand extends BaseMigrateCommand
|
|
|
|
|
{
|
|
|
|
|
public function __construct(Migrator $migrator, Dispatcher $dispatcher)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($migrator, $dispatcher);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Never auto-load database/schema/*.sql — it DROP TABLEs and wipes production data
|
|
|
|
|
* when the migrations table is empty. Use baseline_migrations.sql on existing DBs.
|
|
|
|
|
*/
|
|
|
|
|
protected function prepareDatabase()
|
|
|
|
|
{
|
|
|
|
|
if (! $this->migrator->repositoryExists()) {
|
|
|
|
|
$this->call('migrate:install', array_filter([
|
|
|
|
|
'--database' => $this->option('database'),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|