This commit is contained in:
Ovidiu U
2026-05-12 09:47:26 +01:00
parent 3d103f19e1
commit 759e4f2784
183 changed files with 20094 additions and 0 deletions

1
database/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.sqlite*

View File

@@ -0,0 +1,25 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Tier>
*/
class TierFactory extends Factory
{
public function definition(): array
{
return [
'name' => 'Basic',
'slug' => 'basic',
'description' => 'Basic tier with essential vehicle information',
'allowed_fields' => [
'registrationNumber',
'make',
'colour',
],
];
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\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,
]);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Website>
*/
class WebsiteFactory extends Factory
{
public function definition(): array
{
return [
'name' => fake()->company(),
'domain' => fake()->unique()->domainName(),
'tier_id' => \App\Models\Tier::factory(),
'cache_hit_rate_limit' => 100,
'external_api_rate_limit' => 10,
'is_active' => true,
'bypass_rate_limit' => false,
];
}
}

View File

@@ -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');
}
};

View File

@@ -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');
});
Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->integer('expiration');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cache');
Schema::dropIfExists('cache_locks');
}
};

View File

@@ -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');
}
};

View File

@@ -0,0 +1,34 @@
<?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('vehicle_data_sources', function (Blueprint $table) {
$table->id();
$table->foreignId('vehicle_record_id')->constrained()->cascadeOnDelete();
$table->string('source_name');
$table->string('source_url');
$table->timestamp('last_fetched_at');
$table->timestamp('cache_expires_at');
$table->timestamps();
$table->unique(['vehicle_record_id', 'source_name']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('vehicle_data_sources');
}
};

View File

@@ -0,0 +1,31 @@
<?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('vehicle_records', function (Blueprint $table) {
$table->id();
$table->string('registration_number')->unique();
$table->json('data');
$table->timestamps();
$table->index('registration_number');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('vehicle_records');
}
};

View File

@@ -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('websites', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('domain')->unique();
$table->enum('tier', ['basic', 'standard', 'premium'])->default('basic');
$table->json('tier_fields')->nullable();
$table->integer('cache_hit_rate_limit')->default(100);
$table->integer('external_api_rate_limit')->default(10);
$table->boolean('is_active')->default(true);
$table->boolean('bypass_rate_limit')->default(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('websites');
}
};

View File

@@ -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('api_requests', function (Blueprint $table) {
$table->id();
$table->foreignId('website_id')->constrained()->cascadeOnDelete();
$table->string('registration_number');
$table->string('ip_address');
$table->json('contact_data')->nullable();
$table->enum('response_status', ['cache_hit', 'api_fetched', 'not_found', 'error']);
$table->timestamp('created_at');
$table->index(['website_id', 'created_at']);
$table->index('registration_number');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('api_requests');
}
};

View File

@@ -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');
}
};

View File

@@ -0,0 +1,31 @@
<?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('tiers', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->json('allowed_fields');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tiers');
}
};

View File

@@ -0,0 +1,26 @@
<?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::table('websites', function (Blueprint $table) {
$table->foreignId('tier_id')->after('domain')->nullable()->constrained()->cascadeOnDelete();
$table->dropColumn(['tier', 'tier_fields']);
});
}
public function down(): void
{
Schema::table('websites', function (Blueprint $table) {
$table->dropForeign(['tier_id']);
$table->dropColumn('tier_id');
$table->enum('tier', ['basic', 'standard', 'premium'])->default('basic');
$table->json('tier_fields')->nullable();
});
}
};

View File

@@ -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('api_requests', function (Blueprint $table) {
$table->json('metadata')->nullable()->after('response_status');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('api_requests', function (Blueprint $table) {
$table->dropColumn('metadata');
});
}
};

View File

@@ -0,0 +1,22 @@
<?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::table('api_requests', function (Blueprint $table) {
$table->enum('response_status', ['cache_hit', 'api_fetched', 'not_found', 'error', 'contact_submitted'])->change();
});
}
public function down(): void
{
Schema::table('api_requests', function (Blueprint $table) {
$table->enum('response_status', ['cache_hit', 'api_fetched', 'not_found', 'error'])->change();
});
}
};

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
{
/**
* Seed the application's database.
*/
public function run(): void
{
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
]);
$this->call([
TierSeeder::class,
WebsiteSeeder::class,
]);
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace Database\Seeders;
use App\Models\Tier;
use Illuminate\Database\Seeder;
class TierSeeder extends Seeder
{
public function run(): void
{
Tier::create([
'name' => 'Basic',
'slug' => 'basic',
'description' => 'Basic tier with essential vehicle information',
'allowed_fields' => [
'registrationNumber',
'make',
'colour',
'fuelType',
'yearOfManufacture',
'taxStatus',
'motStatus',
],
]);
Tier::create([
'name' => 'Standard',
'slug' => 'standard',
'description' => 'Standard tier with additional emissions and engine data',
'allowed_fields' => [
'registrationNumber',
'make',
'colour',
'fuelType',
'yearOfManufacture',
'taxStatus',
'motStatus',
'co2Emissions',
'engineCapacity',
'typeApproval',
'euroStatus',
],
]);
Tier::create([
'name' => 'Premium',
'slug' => 'premium',
'description' => 'Premium tier with all available vehicle data',
'allowed_fields' => \App\DataSourceFields::DVLA,
]);
$this->command->info('Tiers seeded successfully!');
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace Database\Seeders;
use App\Models\Tier;
use App\Models\Website;
use Illuminate\Database\Seeder;
class WebsiteSeeder extends Seeder
{
public function run(): void
{
$basicTier = Tier::where('slug', 'basic')->first();
$standardTier = Tier::where('slug', 'standard')->first();
$premiumTier = Tier::where('slug', 'premium')->first();
$basicWebsite = Website::create([
'name' => 'Car Service Basic',
'domain' => 'car-service-basic.test',
'tier_id' => $basicTier->id,
'cache_hit_rate_limit' => 100,
'external_api_rate_limit' => 10,
'is_active' => true,
'bypass_rate_limit' => false,
]);
$standardWebsite = Website::create([
'name' => 'Car Service Standard',
'domain' => 'car-service-standard.test',
'tier_id' => $standardTier->id,
'cache_hit_rate_limit' => 200,
'external_api_rate_limit' => 20,
'is_active' => true,
'bypass_rate_limit' => false,
]);
$premiumWebsite = Website::create([
'name' => 'Car Service Premium',
'domain' => 'car-service-premium.test',
'tier_id' => $premiumTier->id,
'cache_hit_rate_limit' => 500,
'external_api_rate_limit' => 50,
'is_active' => true,
'bypass_rate_limit' => false,
]);
$devWebsite = Website::create([
'name' => 'Development Testing',
'domain' => 'dev.test',
'tier_id' => $premiumTier->id,
'cache_hit_rate_limit' => 1000,
'external_api_rate_limit' => 100,
'is_active' => true,
'bypass_rate_limit' => true,
]);
$basicToken = $basicWebsite->createToken('api-token')->plainTextToken;
$standardToken = $standardWebsite->createToken('api-token')->plainTextToken;
$premiumToken = $premiumWebsite->createToken('api-token')->plainTextToken;
$devToken = $devWebsite->createToken('api-token')->plainTextToken;
$this->command->info('Websites seeded successfully!');
$this->command->newLine();
$this->command->info('Basic Tier Token: '.$basicToken);
$this->command->info('Standard Tier Token: '.$standardToken);
$this->command->info('Premium Tier Token: '.$premiumToken);
$this->command->info('Development Token: '.$devToken);
}
}