/**
  * 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 the console command.
  *
  * @param \Jumilla\Versionia\Laravel\Migrator $migrator
  *
  * @return mixed
  */
 public function handle(Migrator $migrator)
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $seed = $this->argument('name') ?: $migrator->defaultSeed();
     if (!$seed) {
         $this->error('Default seed is not defined.');
         return;
     }
     $class = $migrator->seedClass($seed);
     if (!$class) {
         $this->error("Seed '{$seed}' is not defined.");
         return;
     }
     $this->infoSeedRun($seed, $class);
     $seeder = new $class();
     $seeder->setCommand($this)->run();
 }
 /**
  * Migrate dataase to latest version.
  *
  * @param \Jumilla\Versionia\Laravel\Migrator $migrator
  */
 protected function migrateToLatest(Migrator $migrator)
 {
     $installed_migrations = $migrator->installedLatestMigrations();
     $migration_count = 0;
     foreach ($migrator->migrationGroups() as $group) {
         // [$group => ['version'=>$version, 'class'=>$class]] to $version
         $latest_installed_version = data_get($installed_migrations, $group . '.version', Migrator::VERSION_NULL);
         foreach ($migrator->migrationVersions($group) as $version => $class) {
             if ($migrator->compareMigrationVersion($version, $latest_installed_version) > 0) {
                 $this->line("<info>Up [{$group}/{$version}]</info> Run class <comment>{$class}</comment>");
                 $migrator->doUpgrade($group, $version, $class);
                 ++$migration_count;
             }
         }
     }
     if ($migration_count == 0) {
         $this->line('<info>Nothing to migrate.</info>');
     }
 }
 /**
  * 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);
         }
     }
 }
 /**
  * Execute rollback and upgrade one version.
  *
  * @param \Jumilla\Versionia\Laravel\Migrator $migrator
  * @param string                              $group
  */
 protected function doAgain(Migrator $migrator, $group)
 {
     // retreive installed versions
     $installed_migrations = $migrator->installedLatestMigrations();
     $installed_version = data_get($installed_migrations, $group . '.version', Migrator::VERSION_NULL);
     $definition_versions = $migrator->migrationVersionsByDesc($group);
     if (!$this->checkInstalledVersion($installed_version, $definition_versions)) {
         return;
     }
     // remove migration log
     $definition_latest_version = array_get(array_keys($definition_versions), 0, Migrator::VERSION_NULL);
     if ($migrator->compareMigrationVersion($installed_version, $definition_latest_version) >= 0) {
         $this->line("<info>Remove log [{$group}/{$installed_version}]</info>");
         $migrator->removeMigrationLog($group, $installed_version);
     }
     // downgrade & upgrade
     foreach ($definition_versions as $version => $class) {
         $this->infoDowngrade($group, $version, $class);
         $migrator->doDowngrade($group, $version, $class);
         $this->infoUpgrade($group, $version, $class);
         $migrator->doUpgrade($group, $version, $class);
         break;
     }
 }
 /**
  * Show seed infomation.
  *
  * @param \Jumilla\Versionia\Laravel\Migrator $migrator
  */
 protected function showSeeds(Migrator $migrator)
 {
     $this->line('<comment>Seeds</comment>');
     $seeds = $migrator->seedNames();
     if (count($seeds) > 0) {
         $default_seed = $migrator->defaultSeed();
         foreach ($seeds as $seed) {
             $class = $migrator->seedClass($seed);
             $status_mark = ' ';
             $default_mark = $seed == $default_seed ? '(default)' : '';
             if (!class_exists($class)) {
                 $this->line("{$status_mark} <info>[{$seed}]</info> <error>{$class}</error>");
                 $this->line('');
                 $this->error('Error: Class not found.');
                 continue;
             }
             $this->line("{$status_mark} <comment>{$default_mark}</comment><info>[{$seed}]</info> {$class}");
         }
         if ($default_seed && !in_array($default_seed, $seeds)) {
             $this->line('');
             $this->error("Error: default seed '{$default_seed}' is not defined.");
         }
     } else {
         $this->info('Nothing.');
     }
     $this->line('');
 }