2022-07-26 20:05:14 +08:00
|
|
|
<?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()
|
|
|
|
|
{
|
2023-04-17 18:56:59 +08:00
|
|
|
if (Schema::hasTable('logs')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-26 20:05:14 +08:00
|
|
|
Schema::create('logs', function (Blueprint $table) {
|
|
|
|
|
$table->bigIncrements('id');
|
|
|
|
|
$table->string('module')->comment('模块');
|
|
|
|
|
$table->string('action')->comment('操作');
|
2022-08-01 17:06:43 +08:00
|
|
|
$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('更新后数据');
|
2022-08-03 20:28:42 +08:00
|
|
|
$table->text('message')->nullable()->comment('备注信息');
|
2022-07-26 20:05:14 +08:00
|
|
|
$table->bigInteger('user_id')->comment('操作人id');
|
|
|
|
|
$table->timestamps();
|
2022-08-18 11:22:27 +08:00
|
|
|
// 索引
|
|
|
|
|
$table->index(['target_type', 'target_id', 'target_field']);
|
2022-07-26 20:05:14 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reverse the migrations.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function down()
|
|
|
|
|
{
|
|
|
|
|
Schema::dropIfExists('logs');
|
|
|
|
|
}
|
|
|
|
|
}
|