43 lines
1.3 KiB
PHP
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');
|
|
}
|
|
};
|