<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class MealFoodTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('meal_food', function (Blueprint $table) {
            $table->bigIncrements('meal_food_id');
            $table->unsignedBigInteger('meal_id');
            $table->unsignedBigInteger('food_id');
            $table->unsignedInteger('position');
            $table->timestamps();

            $table->unique(['meal_id', 'food_id'], 'idx_meal_food');

            $table->foreign('meal_id')->references('id')
                ->on('meals')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('food_id')->references('id')
                ->on('food')->onDelete('CASCADE')->onUpdate('CASCADE');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('meal_food');
    }
}
