forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigrateStatus.php
More file actions
70 lines (56 loc) · 1.66 KB
/
Copy pathMigrateStatus.php
File metadata and controls
70 lines (56 loc) · 1.66 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
<?php namespace CodeIgniter\Commands\Database;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Services;
/**
* Displays a list of all migrations and whether they've been run or not.
*
* @package CodeIgniter\Commands
*/
class MigrateStatus extends BaseCommand
{
protected $group = 'Database';
/**
* The Command's name
*
* @var string
*/
protected $name = 'migrate:status';
/**
* the Command's short description
*
* @var string
*/
protected $description = 'Displays a list of all migrations and whether they\'ve been run or not.';
/**
* Displays a list of all migrations and whether they've been run or not.
*/
public function run(array $params=[])
{
$runner = Services::migrations();
$migrations = $runner->findMigrations();
$history = $runner->getHistory();
if (empty($migrations))
{
return CLI::error(lang('Migrations.migNoneFound'));
}
$max = 0;
foreach ($migrations as $version => $file)
{
$file = substr($file, strpos($file, $version.'_'));
$migrations[$version] = $file;
$max = max($max, strlen($file));
}
CLI::write(str_pad(lang('Migrations.filename'), $max+4).lang('Migrations.migOn'), 'yellow');
foreach ($migrations as $version => $file)
{
$date = '';
foreach ($history as $row)
{
if ($row['version'] != $version) continue;
$date = $row['time'];
}
CLI::write(str_pad($file, $max+4). ($date ? $date : '---'));
}
}
}