40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
use App\Models\Entry;
|
|
use App\Models\Event;
|
|
use App\Models\Student;
|
|
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('doublers', function (Blueprint $table) {
|
|
// Foreign keys that will form the composite primary key
|
|
$table->foreignIdFor(Student::class)->constrained()->cascadeOnDelete()->cascadeOnUpdate();
|
|
$table->foreignIdFor(Event::class)->constrained()->cascadeOnDelete()->cascadeOnUpdate();
|
|
|
|
// Doubler Specific Fields
|
|
$table->integer('entry_count');
|
|
$table->foreignIdFor(Entry::class, 'accepted_entry')->nullable()->constrained('entries')->cascadeOnDelete()->cascadeOnUpdate();
|
|
|
|
// Set the composite primary key
|
|
$table->primary(['student_id', 'event_id']);
|
|
$table->timestamps();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*/
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('doublers');
|
|
}
|
|
};
|