1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Ship\Command; |
4
|
|
|
|
5
|
|
|
use Rudra\Container\Facades\Rudra; |
6
|
|
|
use Rudra\Cli\ConsoleFacade as Cli; |
7
|
|
|
use App\Ship\Utils\Database\LoggerAdapter; |
8
|
|
|
|
9
|
|
|
class MigrateCommand extends LoggerAdapter |
10
|
|
|
{ |
11
|
|
|
public function __construct() |
12
|
|
|
{ |
13
|
|
|
$this->table = "rudra_migrations"; |
14
|
|
|
parent::__construct(); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function actionIndex(): void |
18
|
|
|
{ |
19
|
|
|
Cli::printer("Enter container (empty for Ship): ", "magneta"); |
20
|
|
|
$container = ucfirst(str_replace(PHP_EOL, "", Cli::reader())); |
21
|
|
|
|
22
|
|
|
if (!empty($container)) { |
23
|
|
|
$fileList = array_slice(scandir(str_replace('/', DIRECTORY_SEPARATOR, Rudra::config()->get('app.path') . "/app/Containers/" . $container . "/Migration/")), 2); |
24
|
|
|
$namespace = "App\\Containers\\$container\\Migration\\"; |
25
|
|
|
} else { |
26
|
|
|
$fileList = array_slice(scandir(str_replace('/', DIRECTORY_SEPARATOR, Rudra::config()->get('app.path') . "/app/Ship/Migration/")), 2); |
27
|
|
|
$namespace = "App\\Ship\\Migration\\"; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if (!$this->isTable()) { |
31
|
|
|
$this->up(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
foreach ($fileList as $filename) { |
35
|
|
|
$migrationName = $namespace . strstr($filename, '.', true); |
36
|
|
|
|
37
|
|
|
if ($this->checkLog($migrationName)) { |
38
|
|
|
Cli::printer("The $migrationName is already migrated" . PHP_EOL, "light_yellow"); |
39
|
|
|
} else { |
40
|
|
|
(new $migrationName)->up(); |
41
|
|
|
Cli::printer("The $migrationName has migrate" . PHP_EOL, "light_green"); |
42
|
|
|
$this->writeLog($migrationName); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|