'Set database group', ]; /** * Namespaces to ignore when looking for migrations. * * @var type */ protected $ignoredNamespaces = [ 'CodeIgniter', 'Config', 'Tests\Support', ]; /** * Displays a list of all migrations and whether they've been run or not. * * @param array $params */ public function run(array $params = []) { $runner = Services::migrations(); $group = $params['-g'] ?? CLI::getOption('g'); if (! is_null($group)) { $runner->setGroup($group); } // Get all namespaces from PSR4 paths. $config = new Autoload(); $namespaces = $config->psr4; // Loop for all $namespaces foreach ($namespaces as $namespace => $path) { if (in_array($namespace, $this->ignoredNamespaces)) { continue; } $runner->setNamespace($namespace); $migrations = $runner->findMigrations(); $history = $runner->getHistory(); CLI::write($namespace); if (empty($migrations)) { CLI::error(lang('Migrations.noneFound')); continue; } ksort($migrations); $max = 0; foreach ($migrations as $version => $migration) { $file = substr($migration->name, strpos($migration->name, $version . '_')); $migrations[$version]->name = $file; $max = max($max, strlen($file)); } CLI::write(' ' . str_pad(lang('Migrations.filename'), $max + 4) . lang('Migrations.on'), 'yellow'); foreach ($migrations as $uid => $migration) { $date = ''; foreach ($history as $row) { if ($runner->getObjectUid($row) !== $uid) { continue; } $date = date('Y-m-d H:i:s', $row->time); } CLI::write(str_pad(' ' . $migration->name, $max + 6) . ($date ? $date : '---')); } } } }