first commit from hostslim

This commit is contained in:
2026-03-24 21:12:21 +01:00
commit 20fee7784c
252 changed files with 27385 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
*.sqlite*
@@ -0,0 +1,48 @@
<?php
namespace Database\Factories;
use App\Models\AnalyticsSession;
use App\Models\Visitor;
use App\Models\Website;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/** @extends Factory<AnalyticsSession> */
class AnalyticsSessionFactory extends Factory
{
public function definition(): array
{
$started = now()->subMinutes(fake()->numberBetween(1, 60));
return [
'website_id' => Website::factory(),
'visitor_id' => Visitor::factory(),
'uid' => Str::random(32),
'started_at' => $started,
'ended_at' => $started->copy()->addSeconds(fake()->numberBetween(10, 600)),
'duration' => fake()->numberBetween(10, 600),
'is_bounce' => false,
'entry_page' => '/',
'exit_page' => '/about',
'pages_count' => fake()->numberBetween(1, 10),
'ip_address' => fake()->ipv4(),
'referrer_url' => null,
'referrer_domain' => null,
'utm_source' => null,
'utm_medium' => null,
'utm_campaign' => null,
'utm_term' => null,
'utm_content' => null,
];
}
public function bounce(): static
{
return $this->state([
'is_bounce' => true,
'pages_count' => 1,
'duration' => 0,
]);
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace Database\Factories;
use App\Models\AnalyticsSession;
use App\Models\Event;
use App\Models\Visitor;
use App\Models\Website;
use Illuminate\Database\Eloquent\Factories\Factory;
/** @extends Factory<Event> */
class EventFactory extends Factory
{
public function definition(): array
{
return [
'website_id' => Website::factory(),
'visitor_id' => Visitor::factory(),
'analytics_session_id' => AnalyticsSession::factory(),
'name' => fake()->randomElement(['click', 'signup', 'purchase', 'download']),
'category' => fake()->randomElement(['engagement', 'conversion', 'navigation']),
'action' => fake()->word(),
'label' => fake()->word(),
'value' => fake()->optional(0.5)->randomFloat(2, 1, 100),
'properties' => null,
'occurred_at' => now(),
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace Database\Factories;
use App\Models\AnalyticsSession;
use App\Models\Goal;
use App\Models\GoalConversion;
use App\Models\Visitor;
use App\Models\Website;
use Illuminate\Database\Eloquent\Factories\Factory;
/** @extends Factory<GoalConversion> */
class GoalConversionFactory extends Factory
{
public function definition(): array
{
return [
'goal_id' => Goal::factory(),
'website_id' => Website::factory(),
'visitor_id' => Visitor::factory(),
'analytics_session_id' => AnalyticsSession::factory(),
'value' => fake()->randomFloat(2, 1, 100),
'converted_at' => now(),
];
}
}
+63
View File
@@ -0,0 +1,63 @@
<?php
namespace Database\Factories;
use App\Models\Goal;
use App\Models\Website;
use Illuminate\Database\Eloquent\Factories\Factory;
/** @extends Factory<Goal> */
class GoalFactory extends Factory
{
public function definition(): array
{
return [
'website_id' => Website::factory(),
'name' => fake()->sentence(2),
'type' => 'url_destination',
'conditions' => ['path' => '/thank-you', 'match_type' => 'exact'],
'default_value' => fake()->randomFloat(2, 1, 100),
'is_active' => true,
];
}
public function urlDestination(string $path = '/thank-you', string $matchType = 'exact'): static
{
return $this->state([
'type' => 'url_destination',
'conditions' => ['path' => $path, 'match_type' => $matchType],
]);
}
public function eventMatch(string $eventName, ?string $category = null): static
{
return $this->state([
'type' => 'event_match',
'conditions' => array_filter([
'event_name' => $eventName,
'event_category' => $category,
]),
]);
}
public function duration(int $seconds): static
{
return $this->state([
'type' => 'duration',
'conditions' => ['seconds' => $seconds],
]);
}
public function pagesPerSession(int $count): static
{
return $this->state([
'type' => 'pages_per_session',
'conditions' => ['page_count' => $count],
]);
}
public function inactive(): static
{
return $this->state(['is_active' => false]);
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use App\Models\AnalyticsSession;
use App\Models\PageView;
use App\Models\Visitor;
use App\Models\Website;
use Illuminate\Database\Eloquent\Factories\Factory;
/** @extends Factory<PageView> */
class PageViewFactory extends Factory
{
public function definition(): array
{
return [
'website_id' => Website::factory(),
'visitor_id' => Visitor::factory(),
'analytics_session_id' => AnalyticsSession::factory(),
'url' => fake()->url(),
'path' => '/'.fake()->slug(2),
'title' => fake()->sentence(3),
'referrer' => null,
'time_on_page' => fake()->numberBetween(5, 300),
'viewed_at' => now(),
];
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends Factory<User>
*/
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace Database\Factories;
use App\Models\Visitor;
use App\Models\Website;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/** @extends Factory<Visitor> */
class VisitorFactory extends Factory
{
public function definition(): array
{
return [
'website_id' => Website::factory(),
'uid' => Str::random(32),
'first_seen_at' => now(),
'last_seen_at' => now(),
'device_type' => fake()->randomElement(['desktop', 'mobile', 'tablet']),
'browser' => fake()->randomElement(['Chrome', 'Firefox', 'Safari', 'Edge']),
'browser_version' => fake()->numerify('##.#'),
'os' => fake()->randomElement(['Windows', 'macOS', 'Linux', 'iOS', 'Android']),
'os_version' => fake()->numerify('##.#'),
'screen_resolution' => fake()->randomElement(['1920x1080', '1366x768', '390x844']),
'language' => fake()->randomElement(['en', 'de', 'fr', 'es']),
'country' => fake()->countryCode(),
'region' => fake()->state(),
'city' => fake()->city(),
];
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace Database\Factories;
use App\Models\User;
use App\Models\Website;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/** @extends Factory<Website> */
class WebsiteFactory extends Factory
{
public function definition(): array
{
return [
'user_id' => User::factory(),
'name' => fake()->company(),
'domain' => fake()->domainName(),
'tracking_id' => 'TA-'.strtoupper(Str::random(10)),
'is_active' => true,
'settings' => [],
];
}
public function inactive(): static
{
return $this->state(['is_active' => false]);
}
}
@@ -0,0 +1,49 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->integer('expiration')->index();
});
Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->integer('expiration')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cache');
Schema::dropIfExists('cache_locks');
}
};
@@ -0,0 +1,57 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('jobs', function (Blueprint $table) {
$table->id();
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->longText('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
Schema::dropIfExists('job_batches');
Schema::dropIfExists('failed_jobs');
}
};
@@ -0,0 +1,29 @@
<?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('websites', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('name');
$table->string('domain');
$table->string('tracking_id')->unique();
$table->boolean('is_active')->default(true);
$table->json('settings')->nullable();
$table->timestamps();
$table->index('domain');
});
}
public function down(): void
{
Schema::dropIfExists('websites');
}
};
@@ -0,0 +1,38 @@
<?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('visitors', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->string('uid', 64)->index();
$table->timestamp('first_seen_at');
$table->timestamp('last_seen_at');
$table->string('device_type', 20)->nullable();
$table->string('browser', 50)->nullable();
$table->string('browser_version', 20)->nullable();
$table->string('os', 50)->nullable();
$table->string('os_version', 20)->nullable();
$table->string('screen_resolution', 20)->nullable();
$table->string('language', 10)->nullable();
$table->string('country', 2)->nullable();
$table->string('region', 100)->nullable();
$table->string('city', 100)->nullable();
$table->timestamps();
$table->unique(['website_id', 'uid']);
$table->index('country');
});
}
public function down(): void
{
Schema::dropIfExists('visitors');
}
};
@@ -0,0 +1,43 @@
<?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('analytics_sessions', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->foreignId('visitor_id')->constrained()->cascadeOnDelete();
$table->string('uid', 64)->unique();
$table->timestamp('started_at');
$table->timestamp('ended_at')->nullable();
$table->unsignedInteger('duration')->default(0);
$table->boolean('is_bounce')->default(true);
$table->text('entry_page')->nullable();
$table->text('exit_page')->nullable();
$table->unsignedSmallInteger('pages_count')->default(0);
$table->string('ip_address', 45)->nullable();
$table->string('referrer_url')->nullable();
$table->string('referrer_domain', 255)->nullable();
$table->string('utm_source', 255)->nullable();
$table->string('utm_medium', 255)->nullable();
$table->string('utm_campaign', 255)->nullable();
$table->string('utm_term', 255)->nullable();
$table->string('utm_content', 255)->nullable();
$table->timestamps();
$table->index(['website_id', 'started_at']);
$table->index('referrer_domain');
$table->index('utm_source');
});
}
public function down(): void
{
Schema::dropIfExists('analytics_sessions');
}
};
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
Schema::create('page_views', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->foreignId('visitor_id')->constrained()->cascadeOnDelete();
$table->foreignId('analytics_session_id')->constrained()->cascadeOnDelete();
$table->text('url');
$table->string('path', 2048);
$table->string('title', 512)->nullable();
$table->string('referrer', 2048)->nullable();
$table->unsignedInteger('time_on_page')->nullable();
$table->timestamp('viewed_at');
$table->timestamps();
$table->index(['website_id', 'viewed_at']);
});
// Index only the first 255 characters of path to avoid key length issues
DB::statement('ALTER TABLE page_views ADD INDEX page_views_path_index (path(255))');
}
public function down(): void
{
Schema::dropIfExists('page_views');
}
};
@@ -0,0 +1,35 @@
<?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('events', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->foreignId('visitor_id')->constrained()->cascadeOnDelete();
$table->foreignId('analytics_session_id')->constrained()->cascadeOnDelete();
$table->string('name');
$table->string('category')->nullable();
$table->string('action')->nullable();
$table->string('label')->nullable();
$table->decimal('value', 15, 4)->nullable();
$table->json('properties')->nullable();
$table->timestamp('occurred_at');
$table->timestamps();
$table->index(['website_id', 'name', 'occurred_at']);
$table->index(['website_id', 'occurred_at']);
$table->index('category');
});
}
public function down(): void
{
Schema::dropIfExists('events');
}
};
@@ -0,0 +1,29 @@
<?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('goals', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->string('name');
$table->string('type', 30);
$table->json('conditions');
$table->decimal('default_value', 15, 4)->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index(['website_id', 'is_active']);
});
}
public function down(): void
{
Schema::dropIfExists('goals');
}
};
@@ -0,0 +1,30 @@
<?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('goal_conversions', function (Blueprint $table) {
$table->id();
$table->foreignId('goal_id')->constrained()->cascadeOnDelete();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->foreignId('visitor_id')->constrained()->cascadeOnDelete();
$table->foreignId('analytics_session_id')->constrained()->cascadeOnDelete();
$table->decimal('value', 15, 4)->nullable();
$table->timestamp('converted_at');
$table->timestamps();
$table->index(['website_id', 'converted_at']);
$table->index(['goal_id', 'converted_at']);
});
}
public function down(): void
{
Schema::dropIfExists('goal_conversions');
}
};
@@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->text('two_factor_secret')
->after('password')
->nullable();
$table->text('two_factor_recovery_codes')
->after('two_factor_secret')
->nullable();
$table->timestamp('two_factor_confirmed_at')
->after('two_factor_recovery_codes')
->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn([
'two_factor_secret',
'two_factor_recovery_codes',
'two_factor_confirmed_at',
]);
});
}
};
@@ -0,0 +1,30 @@
<?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('daily_aggregates', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->date('date');
$table->unsignedInteger('visitors')->default(0);
$table->unsignedInteger('sessions')->default(0);
$table->unsignedInteger('page_views')->default(0);
$table->unsignedInteger('bounce_count')->default(0);
$table->unsignedBigInteger('total_duration')->default(0);
$table->timestamps();
$table->unique(['website_id', 'date']);
});
}
public function down(): void
{
Schema::dropIfExists('daily_aggregates');
}
};
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
Schema::create('page_daily_aggregates', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->date('date');
$table->string('path', 2048);
$table->unsignedInteger('views')->default(0);
$table->unsignedInteger('unique_views')->default(0);
$table->unsignedBigInteger('total_time_on_page')->default(0);
$table->unsignedInteger('bounces')->default(0);
$table->timestamps();
$table->index(['website_id', 'date']);
});
// Create unique constraint with prefix length on path to avoid key length issues
DB::statement('ALTER TABLE page_daily_aggregates ADD UNIQUE page_daily_aggregates_website_id_date_path_unique (website_id, date, path(255))');
}
public function down(): void
{
Schema::dropIfExists('page_daily_aggregates');
}
};
@@ -0,0 +1,58 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
Schema::table('page_views', function (Blueprint $table) {
$table->index('visitor_id', 'pv_visitor_id_idx');
$table->index('analytics_session_id', 'pv_session_id_idx');
});
Schema::table('analytics_sessions', function (Blueprint $table) {
$table->index('visitor_id', 'sess_visitor_id_idx');
$table->index(['website_id', 'is_bounce', 'started_at'], 'sess_bounce_lookup_idx');
});
// Add indexes with prefix length on TEXT columns to avoid key length issues
DB::statement('ALTER TABLE analytics_sessions ADD INDEX sess_entry_page_idx (website_id, entry_page(255))');
DB::statement('ALTER TABLE analytics_sessions ADD INDEX sess_exit_page_idx (website_id, exit_page(255))');
Schema::table('events', function (Blueprint $table) {
$table->index('visitor_id', 'ev_visitor_id_idx');
});
Schema::table('goal_conversions', function (Blueprint $table) {
$table->index('visitor_id', 'gc_visitor_id_idx');
});
}
public function down(): void
{
Schema::table('page_views', function (Blueprint $table) {
$table->dropIndex('pv_visitor_id_idx');
$table->dropIndex('pv_session_id_idx');
});
Schema::table('analytics_sessions', function (Blueprint $table) {
$table->dropIndex('sess_visitor_id_idx');
$table->dropIndex('sess_bounce_lookup_idx');
});
DB::statement('ALTER TABLE analytics_sessions DROP INDEX sess_entry_page_idx');
DB::statement('ALTER TABLE analytics_sessions DROP INDEX sess_exit_page_idx');
Schema::table('events', function (Blueprint $table) {
$table->dropIndex('ev_visitor_id_idx');
});
Schema::table('goal_conversions', function (Blueprint $table) {
$table->dropIndex('gc_visitor_id_idx');
});
}
};
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->morphs('tokenable');
$table->text('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable()->index();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('personal_access_tokens');
}
};
@@ -0,0 +1,25 @@
<?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('funnels', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->string('name');
$table->json('steps'); // [{type: "pageview"|"event", value: "/checkout", label: "Checkout Page"}, ...]
$table->boolean('is_active')->default(true);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('funnels');
}
};
@@ -0,0 +1,24 @@
<?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('segments', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->string('name');
$table->json('filters'); // [{field: "country", operator: "=", value: "DE"}, {field: "device_type", operator: "=", value: "mobile"}]
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('segments');
}
};
@@ -0,0 +1,27 @@
<?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('dashboard_widgets', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->string('title');
$table->string('widget_type'); // metric, chart, top_pages, top_sources, events, conversions
$table->json('config')->nullable(); // {metric: "page_views", chart_type: "line", limit: 5, ...}
$table->unsignedSmallInteger('sort_order')->default(0);
$table->string('size', 10)->default('half'); // full, half, third
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('dashboard_widgets');
}
};
@@ -0,0 +1,40 @@
<?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');
}
};
@@ -0,0 +1,28 @@
<?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('annotations', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->date('date');
$table->string('text');
$table->string('category')->default('general'); // general, deployment, campaign, incident
$table->timestamps();
$table->index(['website_id', 'date']);
});
}
public function down(): void
{
Schema::dropIfExists('annotations');
}
};
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
use WithoutModelEvents;
/**
* Seed the application's database.
*/
public function run(): void
{
// User::factory(10)->create();
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
'password' => bcrypt('password'),
]);
}
}