<?php

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

class CreateTransfersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('transfers', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('employee_id')->nullable();
            $table->integer('from_organization_id')->unsigned();
            $table->integer('from_herd_id')->unsigned();
            $table->integer('from_lot_id')->unsigned();
            $table->integer('to_organization_id')->unsigned();
            $table->integer('to_herd_id')->unsigned();
            $table->integer('to_lot_id')->unsigned();
            $table->integer('breed_id')->unsigned();
            $table->integer('tag_id')->unsigned();
            $table->date('transfer_date')->nullable();
            $table->integer('created_by')->unsigned()->nullable();
            $table->foreign('employee_id')->references('id')->on('employees')->onDelete('cascade');
            $table->foreign('from_organization_id')->references('id')->on('organizations')->onDelete('cascade');
            $table->foreign('from_herd_id')->references('id')->on('herds')->onDelete('cascade');
            $table->foreign('from_lot_id')->references('id')->on('lots')->onDelete('cascade');
            $table->foreign('to_organization_id')->references('id')->on('organizations')->onDelete('cascade');
            $table->foreign('to_herd_id')->references('id')->on('herds')->onDelete('cascade');
            $table->foreign('to_lot_id')->references('id')->on('lots')->onDelete('cascade');
            $table->foreign('breed_id')->references('id')->on('breeds')->onDelete('cascade');
            $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('transfers');
    }
}
