feat: save ai usage

This commit is contained in:
2026-05-24 11:12:04 +02:00
parent 24ec4165a6
commit 8715267361
11 changed files with 629 additions and 40 deletions
@@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('ai_usages', function (Blueprint $table) {
$table->ulid('id')->primary();
$table->foreignUlid('user_id')->nullable()->constrained('users')->nullOnDelete();
$table->string('type', 64);
$table->string('status', 32);
$table->json('input')->nullable();
$table->json('output')->nullable();
$table->string('provider')->nullable();
$table->string('model')->nullable();
$table->unsignedInteger('prompt_tokens')->nullable();
$table->unsignedInteger('completion_tokens')->nullable();
$table->unsignedInteger('total_tokens')->nullable();
$table->text('error_message')->nullable();
$table->string('related_type')->nullable();
$table->string('related_id', 36)->nullable();
$table->timestamps();
$table->index(['user_id', 'type', 'created_at']);
$table->index(['type', 'status', 'created_at']);
$table->index(['related_type', 'related_id']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('ai_usages');
}
};