<?php

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

class CreateUserIdentityTable extends Migration
{

    /**
     * Run the migrations.
     * @return void
     */
    public function up()
    {
        Schema::create('user_identity', function (Blueprint $table) {
            $table->unsignedBigInteger('user_id')->index();
            $table->unsignedBigInteger('identity_id')->index();
            $table->dateTime('started_at')->nullable()->comment('身份的开始时间');
            $table->dateTime('ended_at')->nullable()->comment('角色的结束时间');
            $table->string('serial', '25')->nullable()->comment('身份生成的编号');
            $table->timestamps();

            $table->primary(['user_id', 'identity_id']);
        });
    }

    /**
     * Reverse the migrations.
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_identitie');
    }

}
