<?php

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

class CreateVisitorHitsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('visitor_hits', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedInteger('album_id')->nullable();
            $table->unsignedBigInteger('photo_id')->nullable();
            $table->unsignedInteger('user_id')->nullable();
            $table->string('view_style')->nullable();
            $table->timestamp('hit_at');
            $table->string('ip_address');
            $table->string('user_agent');
            $table->string('session_identifier');
            $table->string('uri', 500);

            $table->foreign('album_id')
                ->references('id')->on('albums')
                ->onDelete('cascade');
            $table->foreign('photo_id')
                ->references('id')->on('photos')
                ->onDelete('cascade');
            $table->foreign('user_id')
                ->references('id')->on('users')
                ->onDelete('cascade');

            $table->timestamps();
        });
    }

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