<?php

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

class Occurrences extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
        Schema::create('occurrences', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('backend_user_id')->nullable();
            $table->nullableTimestamps();

            $table->date('occurrence_date')->nullable();
            $table->string('occurrence_audio', 300)->nullable();
            $table->string('occurrence_video', 300)->nullable();
            $table->boolean('is_on_map')->default(0);
            $table->boolean('is_on_radio')->default(0);
            $table->unsignedInteger('occurrence_image_id')->nullable();

            $table->string('is_story', 10)->nullable();
            $table->unsignedInteger('story_id')->nullable();

            //Meta
            $table->unsignedInteger('meta_image_id')->nullable();
            $table->foreign('meta_image_id')->references('id')
                ->on('media_items')->onDelete('SET NULL')->onUpdate('CASCADE');

            $table->foreign('backend_user_id')->references('id')
                ->on('backend_users')->onDelete('SET NULL')->onUpdate('CASCADE');
            $table->foreign('occurrence_image_id')->references('id')
                ->on('media_items')->onDelete('SET NULL')->onUpdate('CASCADE');
        });
	}

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

}
