<?php

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

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('client_id')->unsigned()->nullable();
            $table->integer('client_designation_id')->unsigned()->nullable();
            $table->string('timezone')->nullable();
            $table->integer('user_group_id')->unsigned()->nullable();
            $table->string('first_name');
            $table->string('last_name');
            $table->string('image')->nullable();
            $table->string('email',50);
            $table->time('in_time')->nullable();
            $table->time('out_time')->nullable();
            $table->tinyInteger('in_time_reduce')->default('0')->comment('in minute: 5 min');
            $table->date('join_date')->nullable();
            $table->tinyInteger('annual_holiday')->default('0');
            $table->tinyInteger('approved_leave')->default('0');
            $table->string('mobile_no',20)->nullable();
            $table->text('present_address')->nullable();
            $table->text('permanent_address')->nullable();
            $table->string('last_login_ip',20)->nullable();
            $table->string('assign_ip',20)->nullable();
            $table->dateTime('last_login_time')->nullable();
            $table->string('password',80);
            $table->tinyInteger('status')->default('1');
            $table->tinyInteger('user_type')->default('0')->comment('0=user, 1=admin');
            $table->rememberToken();
            $table->timestampsTz();
            $table->unique(['email','client_id']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        DB::statement('SET FOREIGN_KEY_CHECKS=0');
        Schema::dropIfExists('users');
        DB::statement('SET FOREIGN_KEY_CHECKS=1');
    }
}
