<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class MigrateInOrder extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'migrate_in_order';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'This method migrate tables in order';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
      $migrations = [
        '2020_11_27_080001_users_table',
        '2020_11_27_080002_category_table',
        '2020_11_27_080003_game_table',
        '2020_11_27_080004_tournament_table',
        '2020_11_27_080005_part_table',
        '2020_11_27_080006_participation_table',
        '2020_11_27_080007_play_table'
      ];

      foreach($migrations as $migration)
      {
         $basePath = 'database/migrations/';
         $migrationName = trim($migration);
         $path = $basePath.$migrationName;
         $this->call('migrate:refresh', [
          '--path' => $path ,
         ]);
      }
    }
}