<?php

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

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('matricule')->unique();
            $table->string('access_token')->unique();
            $table->string('refresh_token')->unique();
            $table->timestamp('expire_at');
            $table->timestamp('last_login_time')->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('last_req_time')->default(DB::raw('CURRENT_TIMESTAMP'));
            $table->longText('device_token')->nullable();
            $table->enum('user_authorization', ['YES', 'NO', 'NONE'])->default('NONE');
            $table->tinyInteger('type_user')->length(1);
            $table->timestamp('created_at')->useCurrent();
            $table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });
    }
    
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
