<?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('table_snapshots', function (Blueprint $table) {
            $table->id();
            $table->foreignId('website_id')->constrained('managed_sites')->cascadeOnDelete();
            $table->string('table_name');
            $table->unsignedBigInteger('row_count')->default(0);
            $table->unsignedBigInteger('size_bytes')->default(0);
            $table->timestamp('last_updated_at')->nullable();
            $table->json('structure')->nullable();
            $table->timestamps();

            $table->unique(['website_id', 'table_name']);
        });
    }

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