File: /home/xedaptot/be.naniguide.com/database/migrations/2026_04_10_200001_create_ad_platforms_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_platforms', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('uid', 32)->unique();
$table->integer('customer_id')->unsigned()->nullable(); // NULL = system (admin-managed)
$table->integer('admin_id')->unsigned()->nullable(); // Admin who created (for system platforms)
$table->string('platform', 20); // meta | google | tiktok | linkedin
$table->string('name', 255);
$table->text('access_token')->nullable(); // encrypted via model cast
$table->text('refresh_token')->nullable(); // encrypted via model cast
$table->timestamp('token_expires_at')->nullable();
$table->string('platform_user_id', 255)->nullable();
$table->string('platform_user_name', 255)->nullable();
$table->json('scopes')->nullable();
$table->string('status', 20)->default('active'); // active | expired | revoked | error
$table->timestamp('last_health_check_at')->nullable();
$table->string('health_status', 20)->default('unknown'); // healthy | degraded | error | unknown
$table->text('health_message')->nullable();
$table->json('metadata')->nullable();
$table->timestamps();
$table->index(['customer_id', 'platform'], 'idx_customer_platform');
});
}
public function down(): void
{
Schema::dropIfExists('ad_platforms');
}
};