<?php

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

class AddUsersColumns extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('last_name', 255);
            $table->string('state', 100);
            $table->string('department', 255)->nullable();
            $table->string('function', 255)->nullable();
            $table->boolean('accepted_terms')->default(false)->nullable();
            $table->timestamp('last_login')->nullable();
            $table->string('image', 255)->nullable();

            // Member
            $table->unsignedBigInteger('member_id')->nullable();
            $table->foreign('member_id')->references('id')
                ->on('members')->onDelete('SET NULL')->onUpdate('CASCADE');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('last_name');
            $table->dropColumn('state');
            $table->dropColumn('department');
            $table->dropColumn('function');
            $table->dropColumn('accepted_terms');
            $table->dropColumn('last_login');
            $table->dropColumn('image');

            $table->dropForeign(['member_id']);
            $table->dropColumn('member_id');
        });
    }
}
