<?php

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

class CreateUserBenchmarkSectionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_benchmark_sections', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger("user_benchmark_id");
            $table->unsignedBigInteger("training_workout_section_id");
            $table->time('time')->nullable();
            $table->boolean('completed')->default(true);
            $table->unsignedInteger('rounds')->nullable();
            $table->unsignedInteger('reps')->nullable();
            $table->boolean('custom_score')->nullable();
            $table->timestamps();

            $table->foreign("user_benchmark_id")->on("user_benchmarks")->references("id")->onDelete("cascade");
            $table->foreign("training_workout_section_id")->on("training_workout_sections")->references("id")->onDelete("restrict");
        });

        Schema::table('user_benchmark_lines',function (Blueprint $table){
            $table->foreign("user_benchmark_section_id")->references("id")->on("user_benchmark_sections")->onDelete("cascade");
        });
    }

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