<?php

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

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

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