erp/database/migrations/2022_07_26_105818_create_logs_table.php

46 lines
1.4 KiB
PHP

<?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()
{
if (Schema::hasTable('logs')) {
return;
}
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->timestamps();
// 索引
$table->index(['target_type', 'target_id', 'target_field']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('logs');
}
}