<?php

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

class CreateSummariesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('summaries', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('member_id');
            $table->integer('year');
            $table->integer('real_number_last_year')->nullable();
            $table->integer('estimated_number_next_year')->nullable();
            $table->unique(['member_id', 'year']);
            $table->timestamps();
        });

        Schema::table('summaries', function (Blueprint $table) {
            $table->foreign('member_id')->references('id')->on('members')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('summaries', function (Blueprint $table) {
            $table->dropForeign('summaries_member_id_foreign');
        });

        Schema::dropIfExists('summaries');
    }
}
