<?php

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

class CreateLogsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('logs', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('module')->comment('模块');
            $table->string('action')->comment('操作');
            $table->string('target_type')->nullable()->comment('目标类型');
            $table->bigInteger('target_id')->nullable()->default(0)->comment('目标id');
            $table->string('target_field')->nullable()->comment('目标字段');
            $table->text('before_update')->nullable()->comment('更新前数据');
            $table->text('after_update')->nullable()->comment('更新后数据');
            $table->text('message')->nullable()->comment('备注信息');
            $table->bigInteger('user_id')->comment('操作人id');
            $table->index(['target_type', 'target_id', 'target_field']);
            $table->timestamps();
        });
    }

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