<?php

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

class CreateCopItemsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('cop_items', function (Blueprint $table) {
            $table->integerIncrements('id');
            $table->nullableTimestamps();
            $table->string('type', 20);
            $table->double('location_lat');
            $table->double('location_lng');
            $table->unsignedInteger('location_zoom');

            $table->unsignedInteger('backend_user_id')->nullable();
            $table->foreign('backend_user_id')->references('id')
                ->on('backend_users')->onDelete('SET NULL')->onUpdate('CASCADE');

            $table->unsignedInteger('cop_topic_id')->nullable();
            $table->foreign('cop_topic_id')->references('id')
                ->on('cop_topics')->onDelete('RESTRICT')->onUpdate('CASCADE');
        });
    }

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