lots of progress

This commit is contained in:
Doar Mihai
2026-01-17 13:46:20 +02:00
parent ab5d3cae98
commit 030a105992
77 changed files with 8507 additions and 20 deletions
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace Database\Factories;
use App\Models\Site;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\BrokenLink>
*/
class BrokenLinkFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$brokenStatusCodes = [404, 500, 503, 403, 410];
return [
'site_id' => Site::factory(),
'url' => fake()->url(),
'status_code' => fake()->randomElement($brokenStatusCodes),
'last_checked_at' => fake()->dateTimeBetween('-14 days', 'now'),
];
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Site>
*/
class SiteFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'user_id' => User::factory(),
'url' => fake()->url(),
'name' => fake()->company() . ' Website',
'monitoring_enabled' => fake()->boolean(80), // 80% chance of being enabled
];
}
}
@@ -0,0 +1,35 @@
<?php
namespace Database\Factories;
use App\Models\Site;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SslCertificate>
*/
class SslCertificateFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$issuers = [
"Let's Encrypt",
'DigiCert Inc',
'Google Trust Services',
'Amazon',
'Cloudflare Inc',
];
return [
'site_id' => Site::factory(),
'issuer' => fake()->randomElement($issuers),
'expires_at' => fake()->dateTimeBetween('now', '+365 days'),
'checked_at' => fake()->dateTimeBetween('-7 days', 'now'),
];
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace Database\Factories;
use App\Models\Site;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\UptimeCheck>
*/
class UptimeCheckFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$statusCodes = [200, 200, 200, 200, 301, 302, 404, 500, 503]; // Weighted towards 200
return [
'site_id' => Site::factory(),
'status_code' => fake()->randomElement($statusCodes),
'response_time_ms' => fake()->numberBetween(50, 5000),
'checked_at' => fake()->dateTimeBetween('-30 days', 'now'),
];
}
}
@@ -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('sites', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->string('url');
$table->string('name');
$table->boolean('monitoring_enabled')->default(true);
$table->timestamps();
// Indexes
$table->index('user_id');
$table->index('monitoring_enabled');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('sites');
}
};
@@ -0,0 +1,36 @@
<?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('uptime_checks', function (Blueprint $table) {
$table->id();
$table->foreignId('site_id')->constrained()->onDelete('cascade');
$table->integer('status_code')->nullable();
$table->integer('response_time_ms')->nullable();
$table->timestamp('checked_at');
$table->timestamp('created_at');
// Indexes
$table->index('site_id');
$table->index('checked_at');
$table->index(['site_id', 'checked_at']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('uptime_checks');
}
};
@@ -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('ssl_certificates', function (Blueprint $table) {
$table->id();
$table->foreignId('site_id')->constrained()->onDelete('cascade');
$table->string('issuer');
$table->timestamp('expires_at');
$table->timestamp('checked_at');
$table->timestamp('created_at');
// Indexes
$table->index('site_id');
$table->index('expires_at');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('ssl_certificates');
}
};
@@ -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('broken_links', function (Blueprint $table) {
$table->id();
$table->foreignId('site_id')->constrained()->onDelete('cascade');
$table->string('url');
$table->integer('status_code')->nullable();
$table->timestamp('last_checked_at');
$table->timestamp('created_at');
// Indexes
$table->index('site_id');
$table->index('last_checked_at');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('broken_links');
}
};
@@ -0,0 +1,36 @@
<?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('notifications', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->string('type');
$table->text('message');
$table->boolean('is_read')->default(false);
$table->timestamp('created_at');
// Indexes
$table->index('user_id');
$table->index('is_read');
$table->index(['user_id', 'is_read']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notifications');
}
};
@@ -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
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->json('notification_preferences')->nullable()->after('email');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('notification_preferences');
});
}
};
+1
View File
@@ -20,6 +20,7 @@ class DatabaseSeeder extends Seeder
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
'password' => bcrypt('password'),
]);
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace Database\Seeders;
use App\Models\Site;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class MonitoringDemoSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// Create a demo user
$user = User::factory()->create([
'name' => 'Demo User',
'email' => 'demo@example.com',
]);
// Create 10 demo sites for the user
Site::factory(10)
->for($user)
->create()
->each(function (Site $site) {
// Create 5-15 uptime checks per site
$site->uptimeChecks()->createMany(
\App\Models\UptimeCheck::factory(rand(5, 15))->make()->toArray()
);
// Create 1-3 SSL certificates per site
$site->sslCertificates()->createMany(
\App\Models\SslCertificate::factory(rand(1, 3))->make()->toArray()
);
// Create 0-5 broken links per site (some sites may have none)
$brokenLinksCount = rand(0, 5);
if ($brokenLinksCount > 0) {
$site->brokenLinks()->createMany(
\App\Models\BrokenLink::factory($brokenLinksCount)->make()->toArray()
);
}
});
$this->command->info('Created 10 demo sites with monitoring data!');
$this->command->info("Login with: {$user->email}");
}
}