新增聊天室成就系统与消息保留策略

This commit is contained in:
pllx
2026-04-30 16:19:49 +08:00
parent 92e3dd0cdf
commit f354516869
26 changed files with 1966 additions and 14 deletions
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* 执行迁移:给聊天消息增加保留类型字段。
*/
public function up(): void
{
Schema::table('messages', function (Blueprint $table) {
$table->string('retention_type', 30)
->default('user_chat')
->index()
->comment('消息保留类型:user_chat/system_notice/game_notice/ephemeral_notice');
});
}
/**
* 回滚迁移:移除聊天消息保留类型字段。
*/
public function down(): void
{
Schema::table('messages', function (Blueprint $table) {
$table->dropColumn('retention_type');
});
}
};
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* 执行迁移:创建用户成就解锁记录表。
*/
public function up(): void
{
Schema::create('user_achievements', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete()->comment('用户ID');
$table->string('achievement_key', 80)->comment('成就唯一标识');
$table->unsignedBigInteger('progress_value')->default(0)->comment('当前进度快照');
$table->timestamp('achieved_at')->nullable()->index()->comment('达成时间');
$table->timestamp('notified_at')->nullable()->comment('通知时间');
$table->json('metadata')->nullable()->comment('成就解锁附加信息');
$table->timestamps();
$table->unique(['user_id', 'achievement_key']);
$table->index(['achievement_key', 'achieved_at']);
});
}
/**
* 回滚迁移:删除用户成就解锁记录表。
*/
public function down(): void
{
Schema::dropIfExists('user_achievements');
}
};
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* 执行迁移:创建用户成就进度快照表。
*/
public function up(): void
{
Schema::create('user_achievement_progress', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete()->comment('用户ID');
$table->string('achievement_key', 80)->comment('成就唯一标识');
$table->unsignedBigInteger('progress_value')->default(0)->comment('当前进度值');
$table->unsignedBigInteger('threshold_value')->default(0)->comment('达成门槛快照');
$table->timestamp('last_scanned_at')->nullable()->index()->comment('最近扫描时间');
$table->timestamps();
$table->unique(['user_id', 'achievement_key']);
});
}
/**
* 回滚迁移:删除用户成就进度快照表。
*/
public function down(): void
{
Schema::dropIfExists('user_achievement_progress');
}
};