<?php

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

class CreateWebsiteMessagesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('website_messages', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title')->comment('消息内容标题');
            $table->string('content')->comment('消息内容');
            $table->string('type',60)->comment('消息类型');
            $table->string('unique_key',100)->comment('类型下唯一的key避免重复写入');
            $table->Integer('role_id')->nullable()->comment('角色id');
            $table->Integer('uid')->nullable()->comment('用户id 存在非0值表示当前uid可见');
            $table->tinyInteger('status')->default(0)->comment('消息状态 0未读 1已读');
            $table->string('extend')->nullable()->comment('拓展字段 后续拓展用');

            $table->index(["role_id","uid"]);
            $table->unique(["type","unique_key"]);
            $table->timestamps();
        });
    }

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