This commit is contained in:
2025-08-12 23:59:32 +08:00
parent ffe1677630
commit 01c73efb1e
20 changed files with 6125 additions and 2 deletions

View File

@@ -0,0 +1,112 @@
<?php
use Phinx\Migration\AbstractMigration;
class CreateRecorderLogsTable extends AbstractMigration
{
/**
* 创建操作记录表
*/
public function up()
{
$table = $this->table('recorder_log', [
'id' => false,
'primary_key' => ['id'],
'engine' => 'InnoDB',
'collation' => 'utf8mb4_general_ci',
'comment' => '操作记录表',
]);
$table->addColumn('id', 'biginteger', [
'identity' => true,
'signed' => false,
'comment' => '记录ID',
])
->addColumn('operation_type', 'string', [
'limit' => 50,
'default' => '',
'comment' => '操作类型',
])
->addColumn('operation_desc', 'string', [
'limit' => 500,
'default' => '',
'comment' => '操作说明',
])
->addColumn('user_id', 'biginteger', [
'signed' => false,
'default' => 0,
'comment' => '操作用户ID',
])
->addColumn('user_nickname', 'string', [
'limit' => 100,
'default' => '',
'comment' => '操作用户昵称',
])
->addColumn('data_type', 'string', [
'limit' => 100,
'default' => '',
'comment' => '操作数据类型',
])
->addColumn('data_id', 'string', [
'limit' => 100,
'default' => '',
'comment' => '操作数据ID',
])
->addColumn('related_type', 'string', [
'limit' => 100,
'default' => '',
'comment' => '关联数据类型',
])
->addColumn('related_id', 'string', [
'limit' => 100,
'default' => '',
'comment' => '关联数据ID',
])
->addColumn('request_method', 'string', [
'limit' => 10,
'default' => '',
'comment' => '请求方法',
])
->addColumn('request_url', 'string', [
'limit' => 500,
'default' => '',
'comment' => '请求URL',
])
->addColumn('request_ip', 'string', [
'limit' => 50,
'default' => '',
'comment' => '请求IP',
])
->addColumn('user_agent', 'string', [
'limit' => 500,
'default' => '',
'comment' => '用户代理',
])
->addColumn('extra_data', 'text', [
'null' => true,
'comment' => '额外数据(JSON格式)',
])
->addColumn('created_at', 'datetime', [
'default' => 'CURRENT_TIMESTAMP',
'comment' => '创建时间',
])
->addColumn('updated_at', 'datetime', [
'default' => 'CURRENT_TIMESTAMP',
'update' => 'CURRENT_TIMESTAMP',
'comment' => '更新时间',
])
->addIndex(['user_id'], ['name' => 'idx_user_id'])
->addIndex(['operation_type'], ['name' => 'idx_operation_type'])
->addIndex(['data_type', 'data_id'], ['name' => 'idx_data_type_id'])
->addIndex(['created_at'], ['name' => 'idx_created_at'])
->create();
}
/**
* 删除操作记录表
*/
public function down()
{
$this->table('recorder_log')->drop()->save();
}
}