Add models, enums, and services for user roles, theme preferences, slug history, and ID generation

This commit is contained in:
pacnpal
2025-02-23 19:50:40 -05:00
parent 32aea21e48
commit 7e5d15eb46
55 changed files with 6462 additions and 4 deletions

View File

@@ -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('park_areas', function (Blueprint $table) {
// Add position field for ordering
$table->integer('position')->default(0);
// Add parent_id for nested areas
$table->foreignId('parent_id')
->nullable()
->constrained('park_areas')
->nullOnDelete();
// Add index for efficient ordering queries
$table->index(['park_id', 'position']);
// Add index for parent relationship queries
$table->index(['park_id', 'parent_id']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('park_areas', function (Blueprint $table) {
$table->dropIndex(['park_id', 'position']);
$table->dropIndex(['park_id', 'parent_id']);
$table->dropForeign(['parent_id']);
$table->dropColumn(['position', 'parent_id']);
});
}
};

View File

@@ -0,0 +1,62 @@
<?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('park_areas', function (Blueprint $table) {
// Ride statistics
$table->integer('ride_count')->default(0);
$table->integer('coaster_count')->default(0);
$table->integer('flat_ride_count')->default(0);
$table->integer('water_ride_count')->default(0);
// Visitor statistics
$table->integer('daily_capacity')->nullable();
$table->integer('peak_wait_time')->nullable();
$table->decimal('average_rating', 3, 2)->nullable();
// Historical data
$table->integer('total_rides_operated')->default(0);
$table->integer('retired_rides_count')->default(0);
$table->date('last_new_ride_added')->nullable();
// Add indexes for common queries
$table->index(['park_id', 'ride_count']);
$table->index(['park_id', 'coaster_count']);
$table->index(['park_id', 'average_rating']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('park_areas', function (Blueprint $table) {
$table->dropIndex(['park_id', 'ride_count']);
$table->dropIndex(['park_id', 'coaster_count']);
$table->dropIndex(['park_id', 'average_rating']);
$table->dropColumn([
'ride_count',
'coaster_count',
'flat_ride_count',
'water_ride_count',
'daily_capacity',
'peak_wait_time',
'average_rating',
'total_rides_operated',
'retired_rides_count',
'last_new_ride_added',
]);
});
}
};

View File

@@ -0,0 +1,80 @@
<?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('parks', function (Blueprint $table) {
// Area statistics
$table->integer('total_areas')->default(0);
$table->integer('operating_areas')->default(0);
$table->integer('closed_areas')->default(0);
// Ride statistics
$table->integer('total_rides')->default(0);
$table->integer('total_coasters')->default(0);
$table->integer('total_flat_rides')->default(0);
$table->integer('total_water_rides')->default(0);
// Visitor statistics
$table->integer('total_daily_capacity')->default(0);
$table->integer('average_wait_time')->nullable();
$table->decimal('average_rating', 3, 2)->nullable();
// Historical data
$table->integer('total_rides_operated')->default(0);
$table->integer('total_rides_retired')->default(0);
$table->date('last_expansion_date')->nullable();
$table->date('last_major_update')->nullable();
// Performance metrics
$table->decimal('utilization_rate', 5, 2)->nullable();
$table->integer('peak_daily_attendance')->nullable();
$table->decimal('guest_satisfaction', 3, 2)->nullable();
// Add indexes for common queries
$table->index(['operator_id', 'total_rides']);
$table->index(['operator_id', 'total_coasters']);
$table->index(['operator_id', 'average_rating']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('parks', function (Blueprint $table) {
$table->dropIndex(['operator_id', 'total_rides']);
$table->dropIndex(['operator_id', 'total_coasters']);
$table->dropIndex(['operator_id', 'average_rating']);
$table->dropColumn([
'total_areas',
'operating_areas',
'closed_areas',
'total_rides',
'total_coasters',
'total_flat_rides',
'total_water_rides',
'total_daily_capacity',
'average_wait_time',
'average_rating',
'total_rides_operated',
'total_rides_retired',
'last_expansion_date',
'last_major_update',
'utilization_rate',
'peak_daily_attendance',
'guest_satisfaction',
]);
});
}
};

View File

@@ -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->string('user_id', 10)->unique()->after('id');
$table->enum('role', ['USER', 'MODERATOR', 'ADMIN', 'SUPERUSER'])->default('USER')->after('remember_token');
$table->boolean('is_banned')->default(false)->after('role');
$table->text('ban_reason')->nullable()->after('is_banned');
$table->timestamp('ban_date')->nullable()->after('ban_reason');
$table->string('pending_email')->nullable()->after('email');
$table->enum('theme_preference', ['light', 'dark'])->default('light')->after('ban_date');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn([
'user_id',
'role',
'is_banned',
'ban_reason',
'ban_date',
'pending_email',
'theme_preference'
]);
});
}
};

View File

@@ -0,0 +1,46 @@
<?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('profiles', function (Blueprint $table) {
$table->id();
$table->string('profile_id', 10)->unique();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->string('display_name', 50)->unique();
$table->string('avatar')->nullable();
$table->string('pronouns', 50)->nullable();
$table->text('bio')->nullable();
// Social media links
$table->string('twitter')->nullable();
$table->string('instagram')->nullable();
$table->string('youtube')->nullable();
$table->string('discord', 100)->nullable();
// Ride statistics
$table->integer('coaster_credits')->default(0);
$table->integer('dark_ride_credits')->default(0);
$table->integer('flat_ride_credits')->default(0);
$table->integer('water_ride_credits')->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('profiles');
}
};

View File

@@ -0,0 +1,58 @@
<?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('operators', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->string('website')->nullable();
$table->string('headquarters')->nullable();
$table->text('description')->nullable();
$table->integer('total_parks')->default(0);
$table->integer('total_rides')->default(0);
$table->timestamps();
});
Schema::create('manufacturers', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->string('website')->nullable();
$table->string('headquarters')->nullable();
$table->text('description')->nullable();
$table->integer('total_rides')->default(0);
$table->integer('total_roller_coasters')->default(0);
$table->timestamps();
});
// Create slug history table for tracking slug changes
Schema::create('slug_histories', function (Blueprint $table) {
$table->id();
$table->morphs('sluggable'); // Creates sluggable_type and sluggable_id
$table->string('slug');
$table->timestamps();
$table->index(['sluggable_type', 'slug']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('slug_histories');
Schema::dropIfExists('manufacturers');
Schema::dropIfExists('operators');
}
};

View File

@@ -0,0 +1,59 @@
<?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('locations', function (Blueprint $table) {
$table->id();
// Polymorphic relationship
$table->morphs('locatable');
// Location details
$table->string('address')->nullable();
$table->string('city');
$table->string('state')->nullable();
$table->string('country');
$table->string('postal_code')->nullable();
// Coordinates
$table->decimal('latitude', 10, 8);
$table->decimal('longitude', 11, 8);
$table->decimal('elevation', 8, 2)->nullable();
// Additional details
$table->string('timezone')->nullable();
$table->json('metadata')->nullable();
$table->boolean('is_approximate')->default(false);
$table->string('source')->nullable();
// Geocoding cache
$table->json('geocoding_data')->nullable();
$table->timestamp('geocoded_at')->nullable();
// Timestamps
$table->timestamps();
// Indexes
$table->index(['latitude', 'longitude']);
$table->index(['country', 'state', 'city']);
$table->index('postal_code');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('locations');
}
};

View File

@@ -0,0 +1,72 @@
<?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('parks', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->string('status', 20);
// Details
$table->date('opening_date')->nullable();
$table->date('closing_date')->nullable();
$table->string('operating_season')->nullable();
$table->decimal('size_acres', 10, 2)->nullable();
$table->string('website')->nullable();
// Statistics
$table->decimal('average_rating', 3, 2)->nullable();
$table->integer('ride_count')->nullable();
$table->integer('coaster_count')->nullable();
// Foreign keys
$table->foreignId('operator_id')
->nullable()
->constrained()
->nullOnDelete();
$table->timestamps();
});
Schema::create('park_areas', function (Blueprint $table) {
$table->id();
$table->foreignId('park_id')
->constrained()
->cascadeOnDelete();
$table->string('name');
$table->string('slug');
$table->text('description')->nullable();
$table->date('opening_date')->nullable();
$table->date('closing_date')->nullable();
$table->timestamps();
// Ensure unique slugs within each park
$table->unique(['park_id', 'slug']);
});
// Create index for park status for efficient filtering
Schema::table('parks', function (Blueprint $table) {
$table->index('status');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('park_areas');
Schema::dropIfExists('parks');
}
};