<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('clicks_by_referrer', function (Blueprint $table) {
            $table->id();
            $table->foreignId('link_id')->constrained()->cascadeOnDelete();
            $table->date('day');
            $table->string('referrer_host', 191)->default('');
            $table->unsignedBigInteger('count')->default(0);
            $table->unique(['link_id', 'day', 'referrer_host']);
            $table->index(['link_id', 'day']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('clicks_by_referrer');
    }
};
