<?php

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

class AddFcmmessagesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('fcm_messages')) {

            Schema::create('fcm_messages', function (Blueprint $table) {

                $table->bigIncrements('id');
                $table->unsignedBigInteger('content_id')->nullable();
                $table->unsignedBigInteger('user_id')->nullable();
                $table->string('content_type', 50);
                $table->string('type', 150);
                $table->string('type_identifier', 512)->nullable;
                $table->string('fcm_id', 512)->nullable;
                $table->json('message_contents')->nullable();
                $table->nullableTimestamps();

                $table->foreign('user_id')->references('id')
                    ->on('users')->onDelete('CASCADE')->onUpdate('CASCADE');
            });
        }
    }

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