2025_11_09_131811_create_messages_table.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. use App\Enums\Status;
  3. use App\Models\Chat;
  4. use Illuminate\Database\Migrations\Migration;
  5. use Illuminate\Database\Schema\Blueprint;
  6. use Illuminate\Support\Facades\Schema;
  7. return new class extends Migration {
  8. /**
  9. * Run the migrations.
  10. */
  11. public function up(): void
  12. {
  13. Schema::create('messages', function (Blueprint $table) {
  14. $table->uuid('id')->primary();
  15. $table->foreignIdFor(Chat::class)->constrained()->cascadeOnUpdate()->cascadeOnDelete();
  16. $table->longText('thinking')->nullable();
  17. $table->longText('content')->nullable();
  18. $table->string('from')->default('user');
  19. $table->integer('tokens_in')->default(0);
  20. $table->integer('tokens_out')->default(0);
  21. $table->jsonb('fields')->nullable();
  22. $table->tinyInteger('status')->default(Status::Completed);
  23. $table->timestamps();
  24. });
  25. }
  26. /**
  27. * Reverse the migrations.
  28. */
  29. public function down(): void
  30. {
  31. Schema::dropIfExists('messages');
  32. }
  33. };