HoshiAI-be/database/migrations/2025_11_11_191436_create_tests_table.php
2025-11-11 21:45:51 +01:00

43 lines
1.3 KiB
PHP

<?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('tests', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('description');
$table->timestamp('closed_at')->nullable();
$table->unsignedBigInteger('category_id')->nullable();
$table->unsignedBigInteger('author_id')->nullable();
$table->foreign('author_id')->references('id')->on('users')->onDelete('set null');
$table->foreign('category_id')->references('id')->on('categories')->onDelete('set null');
$table->timestamps();
});
Schema::create('question_test', function (Blueprint $table) {
$table->foreignId('test_id')->constrained()->cascadeOnDelete();
$table->foreignId('question_id')->constrained()->cascadeOnDelete();
$table->primary(['test_id', 'question_id']);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tests');
}
};