HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/be.naniguide.com/database/migrations/2026_04_10_200011_create_ad_ab_tests_table.php
<?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('ad_ab_tests', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('uid', 32)->unique();
            $table->bigInteger('ad_campaign_id')->unsigned();
            $table->string('status', 20)->default('draft');       // draft | running | completed | cancelled
            $table->bigInteger('winner_variant_id')->unsigned()->nullable();
            $table->decimal('confidence', 5, 2)->default(0);
            $table->json('settings')->nullable();                 // significance threshold, split %, duration
            $table->timestamp('started_at')->nullable();
            $table->timestamp('completed_at')->nullable();
            $table->timestamps();

            $table->foreign('ad_campaign_id')->references('id')->on('ad_campaigns')->onDelete('cascade');
        });

        Schema::create('ad_ab_variants', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('uid', 32)->unique();
            $table->bigInteger('ad_ab_test_id')->unsigned();
            $table->string('name', 255);
            $table->integer('weight')->default(50);                // split weight %
            $table->bigInteger('impressions')->default(0);
            $table->bigInteger('clicks')->default(0);
            $table->decimal('spend', 12, 2)->default(0);
            $table->integer('conversions')->default(0);
            $table->decimal('ctr', 8, 4)->default(0);
            $table->boolean('is_winner')->default(false);
            $table->json('creative_data')->nullable();
            $table->timestamps();

            $table->foreign('ad_ab_test_id')->references('id')->on('ad_ab_tests')->onDelete('cascade');
        });
    }

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