<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateStationTaskChildren extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('station_task_children', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('station_task_id')->index();
            $table->string('station_task_table_type');
            $table->bigInteger('station_task_table_id');
            $table->index('station_task_table_id','station_task_table_type');
            $table->timestamps();
        });
        Schema::table('station_task_batches', function (Blueprint $table) {
            $table->dropColumn('station_id');
        });
        Schema::table('station_task_commodities', function (Blueprint $table) {
            $table->dropColumn('station_id');
        });
        Schema::table('station_task_material_boxes', function (Blueprint $table) {
            $table->dropColumn('station_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('station_task_batches', function (Blueprint $table) {
            $table->integer('station_id')->index();
        });
        Schema::table('station_task_commodities', function (Blueprint $table) {
            $table->integer('station_id')->index();
        });
        Schema::table('station_task_material_boxes', function (Blueprint $table) {
            $table->integer('station_id')->index();
        });
        Schema::dropIfExists('station_task_children');
    }
}
