Refactor Park model, update routes for parks management, and enhance database migrations for park areas and locations

This commit is contained in:
pacnpal
2025-02-25 14:17:13 -05:00
parent 45f9e45b9a
commit 15b2d4ebcf
12 changed files with 301 additions and 151 deletions

View File

@@ -3,6 +3,7 @@
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
{
@@ -11,6 +12,9 @@ return new class extends Migration
*/
public function up(): void
{
// Enable PostGIS extension if not enabled
DB::statement('CREATE EXTENSION IF NOT EXISTS postgis');
Schema::create('locations', function (Blueprint $table) {
$table->id();
@@ -24,9 +28,6 @@ return new class extends Migration
$table->string('country');
$table->string('postal_code')->nullable();
// Enable PostGIS extension if not enabled
DB::statement('CREATE EXTENSION IF NOT EXISTS postgis');
// Location name and type
$table->string('name')->nullable();
$table->string('location_type', 50)->nullable();
@@ -36,7 +37,7 @@ return new class extends Migration
$table->decimal('longitude', 9, 6)->nullable();
// Coordinates using PostGIS
$table->point('coordinates')->spatialIndex();
// We'll add the coordinates column after the table is created
$table->decimal('elevation', 8, 2)->nullable();
// Additional details
@@ -58,6 +59,10 @@ return new class extends Migration
$table->index('name');
$table->index('location_type');
});
// Add the coordinates column using PostGIS
DB::statement('ALTER TABLE locations ADD COLUMN coordinates GEOMETRY(Point, 4326)');
DB::statement('CREATE INDEX locations_coordinates_idx ON locations USING GIST (coordinates)');
}
/**

View File

@@ -18,15 +18,14 @@ return new class extends Migration
$table->integer('closed_areas')->default(0);
// Ride statistics
$table->integer('total_rides')->default(0);
$table->integer('total_coasters')->default(0);
// Note: ride_count and coaster_count already exist in the parks table
$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();
// Note: average_rating already exists in the parks table
// Historical data
$table->integer('total_rides_operated')->default(0);
@@ -40,8 +39,8 @@ return new class extends Migration
$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', 'ride_count']);
$table->index(['operator_id', 'coaster_count']);
$table->index(['operator_id', 'average_rating']);
});
}
@@ -52,21 +51,18 @@ return new class extends Migration
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', 'ride_count']);
$table->dropIndex(['operator_id', 'coaster_count']);
$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',