Files
analytics/database/migrations/2026_03_19_200004_create_alerts_table.php
T
2026-03-24 21:12:21 +01:00

41 lines
1.4 KiB
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('alerts', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->string('name');
$table->string('metric'); // page_views, visitors, sessions, bounce_rate, goal_conversions
$table->string('condition'); // above, below, change_up, change_down
$table->decimal('threshold', 12, 2);
$table->string('period')->default('daily'); // daily, hourly
$table->string('channel')->default('email'); // email, in_app, both
$table->boolean('is_active')->default(true);
$table->timestamp('last_triggered_at')->nullable();
$table->timestamps();
});
Schema::create('alert_notifications', function (Blueprint $table) {
$table->id();
$table->foreignId('alert_id')->constrained()->cascadeOnDelete();
$table->decimal('value', 12, 2);
$table->text('message');
$table->boolean('is_read')->default(false);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('alert_notifications');
Schema::dropIfExists('alerts');
}
};