Files
chatroom/database/migrations/2026_02_26_132600_create_ai_tables.php
lkddi aeffb8e4d4 整理:合并零散迁移文件,36个简化为24个纯建表迁移
- users 表:吸收 s_color类型变更/sign/question/answer/vip_level_id/has_received_new_gift
- rooms 表:吸收 visit_num、announcement
- sysparam 表:吸收全部 seed(99级经验/权限等级/钓鱼/魅力/排行榜,直接写最终值)
- 新增 create_shop_tables(shop_items+user_purchases+username_blacklist+默认商品)
- 新增 create_user_currency_logs_table(积分流水表含完整索引)
- 删除 14 个已吸收的 add_column / seed 零散迁移
2026-02-28 14:03:04 +08:00

71 lines
3.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 文件功能:创建 AI 厂商配置表和 AI 使用日志表
*
* ai_provider_configs — 存储多个 AI 厂商的 API 配置(密钥、端点、模型等)
* ai_usage_logs — 记录每次 AI 接口调用的 token 消耗和响应信息
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* 执行迁移:创建 AI 相关的两张数据表
*/
public function up(): void
{
// AI 厂商配置表
Schema::create('ai_provider_configs', function (Blueprint $table) {
$table->id();
$table->string('provider', 50)->index()->comment('厂商标识(如 deepseek, qwen, openai');
$table->string('name', 100)->comment('厂商显示名称');
$table->text('api_key')->comment('API Key加密存储');
$table->string('api_endpoint', 255)->comment('API 端点地址');
$table->string('model', 100)->comment('使用的模型名称');
$table->decimal('temperature', 3, 2)->default(0.30)->comment('温度参数');
$table->integer('max_tokens')->default(2048)->comment('最大 Token 数');
$table->boolean('is_enabled')->default(true)->index()->comment('是否启用');
$table->boolean('is_default')->default(false)->comment('是否为默认厂商');
$table->integer('sort_order')->default(0)->comment('排序(故障转移时按此顺序)');
$table->timestamps();
});
// AI 使用日志表
Schema::create('ai_usage_logs', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete()->comment('使用者');
$table->string('provider', 50)->comment('AI 厂商标识');
$table->string('model', 100)->comment('使用的模型');
$table->string('action', 50)->default('chatbot')->comment('操作类型');
$table->integer('prompt_tokens')->default(0)->comment('输入 Token 数');
$table->integer('completion_tokens')->default(0)->comment('输出 Token 数');
$table->integer('total_tokens')->default(0)->comment('总 Token 数');
$table->decimal('cost', 10, 6)->default(0)->comment('费用');
$table->integer('response_time_ms')->default(0)->comment('响应时间(毫秒)');
$table->boolean('success')->default(true)->comment('是否成功');
$table->text('error_message')->nullable()->comment('错误信息');
$table->timestamps();
// 索引
$table->index(['provider', 'created_at']);
});
}
/**
* 回滚迁移:删除 AI 相关的两张数据表
*/
public function down(): void
{
Schema::dropIfExists('ai_usage_logs');
Schema::dropIfExists('ai_provider_configs');
}
};