/** * Execute the console command. * * @param \Jumilla\Versionia\Laravel\Migrator $migrator * * @return mixed */ public function handle(Migrator $migrator) { if (!$this->confirmToProceed()) { return; } $migrator->makeLogTable(); $installed_migrations = $migrator->installedMigrationsByDesc(); foreach ($installed_migrations as $group => $migrations) { foreach ($migrations as $data) { $this->infoDowngrade($group, $data->version, $data->class); $migrator->doDowngrade($group, $data->version); } } }
/** * Execute clean and upgrade. * * @param \Jumilla\Versionia\Laravel\Migrator $migrator */ protected function doRefresh(Migrator $migrator) { // retreive installed versions $installed_migrations = $migrator->installedMigrationsByDesc(); // downgrade foreach ($installed_migrations as $group => $migrations) { foreach ($migrations as $data) { $this->infoDowngrade($group, $data->version, $data->class); $migrator->doDowngrade($group, $data->version); } } // upgrade foreach ($migrator->migrationGroups() as $group) { foreach ($migrator->migrationVersions($group) as $version => $class) { $this->infoUpgrade($group, $version, $class); $migrator->doUpgrade($group, $version, $class); } } }
/** * Show migration infomation. * * @param \Jumilla\Versionia\Laravel\Migrator $migrator */ protected function showMigrations(Migrator $migrator) { $this->line('<comment>Migrations</comment>'); $groups = $migrator->migrationGroups(); if (count($groups) > 0) { // get [$group => $items] $installed_migrations = $migrator->installedMigrationsByDesc(); foreach ($groups as $group) { // [$items] to [$installed_versions] $installed_versions = $installed_migrations->get($group, collect())->pluck('version'); // [$versions] to $latest_version $latest_installed_version = $installed_versions->get(0, Migrator::VERSION_NULL); // enum definition foreach ($migrator->migrationVersionsByDesc($group) as $version => $class) { $installed = $installed_versions->contains($version); if ($version === $latest_installed_version) { $mark = '*'; } else { $mark = $installed ? '-' : ' '; } if (!class_exists($class)) { $this->line("{$mark} <info>[{$group}/{$version}]</info> <error>{$class}</error>"); $this->line(''); $this->error('Error: Class not found.'); continue; } $migration = new $class(); if (!$migration instanceof Migration) { $this->line("{$mark} <info>[{$group}/{$version}]</info> <error>{$class}</error>"); $this->line(''); $this->error('Error: Must inherit from class "Illuminate\\Database\\Migrations\\Migration".'); continue; } $this->line("{$mark} <info>[{$group}/{$version}]</info> {$class}"); } $this->line(''); } } else { $this->info('Nothing.'); $this->line(''); } }