<?php

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

class CreateUserTrainingSessionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_training_sessions', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger("user_id")->nullable();
            $table->unsignedBigInteger("training_session_id")->nullable();
            $table->string("type")->nullable()->index();
            $table->timestamps();

            $table->unique(["user_id", "training_session_id"]);

            $table->foreign("user_id")->references("id")->on("users")->onDelete("set null");
            $table->foreign("training_session_id")->references("id")->on("training_sessions")->onDelete("set null");
        });
    }

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