<?php

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

class AddApprovatedFieldToMemberChildrens extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('summaries', function (Blueprint $table) {
            $table->timestamp('approved_at')->after('estimated_number_next_year')->nullable()->default(null);
            $table->unsignedInteger('revisor_id')->after('estimated_number_next_year')->nullable();
            $table->foreign('revisor_id')->references('id')->on('users');
        });

        Schema::table('contacts', function (Blueprint $table) {
            $table->timestamp('approved_at')->after('house_number_cc')->nullable()->default(null);
            $table->unsignedInteger('revisor_id')->after('house_number_cc')->nullable();
            $table->foreign('revisor_id')->references('id')->on('users');
        });

        Schema::table('addresses', function (Blueprint $table) {
            $table->timestamp('approved_at')->after('job_title_representative')->nullable()->default(null);
            $table->unsignedInteger('revisor_id')->after('job_title_representative')->nullable();
            $table->foreign('revisor_id')->references('id')->on('users');
        });
    }

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

        Schema::table('contacts', function (Blueprint $table) {
            $table->dropColumn('approved_at');
            $table->dropForeign('contacts_revisor_id_foreign');
        });

        Schema::table('addresses', function (Blueprint $table) {
            $table->dropColumn('approved_at');
            $table->dropForeign('addresses_revisor_id_foreign');
        });
    }
}
