app/database/migrations/2025_02_08_231219_create_schedules_table.php

42 lines
1.4 KiB
PHP
Executable file

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('schedules', function (Blueprint $table) {
$table->id();
$table->foreignId('planner_id')->constrained()->cascadeOnDelete();
$table->date('date');
$table->boolean('is_skipped')->default(false);
$table->unique(['planner_id', 'date']);
});
Schema::create('scheduled_user_dishes', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('schedule_id');
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('user_dish_id')->nullable();
$table->boolean('is_skipped')->default(false);
$table->timestamps();
$table->foreign('schedule_id')->references('id')->on('schedules')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('user_dish_id')->references('id')->on('user_dishes')->onDelete('cascade');
$table->unique(['schedule_id', 'user_id']);
$table->index('user_dish_id');
});
}
public function down(): void
{
Schema::dropIfExists('scheduled_user_dishes');
Schema::dropIfExists('schedules');
}
};