<?php

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

class CreateCourseNotificationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('course_notifications', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('learning_product_id');
            $table->dateTime('date', 0)->nullable();
            $table->string('time', 0)->nullable();
            $table->string('subject')->nullable();
            $table->longText('message')->nullable();
            $table->json('emails');
            $table->json('users');
            $table->timestamps();
        });

        Schema::table('course_notifications', function (Blueprint $table) {
            $table->foreign('learning_product_id')->references('id')->on('learning_products')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('course_notifications', function (Blueprint $table) {
            $table->dropForeign('course_notifications_learning_product_id_foreign');
        });

        Schema::dropIfExists('course_notifications');
    }
}
