forked from doppar/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigrateCommand.php
More file actions
75 lines (63 loc) · 1.86 KB
/
MigrateCommand.php
File metadata and controls
75 lines (63 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Phaseolies\Console\Commands\Migrations;
use Phaseolies\Console\Schedule\Command;
use Phaseolies\Database\Migration\Migrator;
class MigrateCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $name = 'migrate {--path=} {--connection=}';
/**
* The description of the console command.
*
* @var string
*/
protected $description = 'Run the database migrations';
/**
* The migrator instance.
*
* @var Migrator
*/
protected Migrator $migrator;
/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
$this->migrator = app('migrator');
}
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
return $this->executeWithTiming(function () {
$connection = $this->option('connection') ?: config('database.default');
$path = $this->option('path');
$this->line("<fg=yellow>🔁 Running migrations on connection: {$connection}</>");
$this->newLine();
if ($path) {
$migrations = $this->migrator->run($connection, $path);
} else {
$migrations = $this->migrator->run($connection);
}
if (empty($migrations)) {
$this->newLine();
$this->displayInfo('Nothing to migrate');
} else {
$this->displaySuccess('Database migrated successfully');
$this->line('<fg=yellow>📊 Migrations Executed:</>');
foreach ($migrations as $migration) {
$this->line('- <fg=white>' . $migration . '</>');
}
}
return Command::SUCCESS;
});
}
}