# Rides System Database Schema

## Overview
The rides system uses three primary tables to manage ride data:
1. `ride_models` - Templates for specific ride types/models
2. `rides` - Individual ride installations at parks
3. `roller_coaster_stats` - Extended statistics for roller coasters

## Implementation Details

### Migration Files
- `2024_02_25_194500_create_ride_models_table.php`
- `2024_02_25_194600_create_rides_table.php`
- `2024_02_25_194700_create_roller_coaster_stats_table.php`

### RideModels Table
- Primary key: `id`
- Base information:
  - `name`: string, required
  - `description`: text, default empty
  - `category`: string(2), using RideCategory enum
- Relationships:
  - `manufacturer_id`: nullable foreign key to manufacturers
- Constraints:
  - Unique combination of manufacturer_id and name
  - Manufacturer can be null (for generic models)

### Rides Table
- Primary key: `id`
- Base information:
  - `name`: string, required
  - `slug`: string, required
  - `description`: text, default empty
- Relationships:
  - `park_id`: required foreign key to parks
  - `park_area_id`: nullable foreign key to park_areas
  - `manufacturer_id`: nullable foreign key to manufacturers
  - `designer_id`: nullable foreign key to designers
  - `ride_model_id`: nullable foreign key to ride_models
- Status fields:
  - `category`: string(2), RideCategory enum
  - `status`: string(20), RideStatus enum
  - `post_closing_status`: string(20), nullable
  - `status_since`: date, nullable
- Operational dates:
  - `opening_date`: date, nullable
  - `closing_date`: date, nullable
- Physical characteristics:
  - `min_height_in`: unsigned integer, nullable
  - `max_height_in`: unsigned integer, nullable
  - `capacity_per_hour`: unsigned integer, nullable
  - `ride_duration_seconds`: unsigned integer, nullable
- User interaction:
  - `average_rating`: decimal(3,2), nullable
- Timestamps: `created_at`, `updated_at`
- Indexes:
  - Unique: [park_id, slug]
  - Regular: category, status, manufacturer_id, designer_id, ride_model_id

### RollerCoasterStats Table
- Primary key: `id`
- Relationship:
  - `ride_id`: unique foreign key to rides (one-to-one)
- Physical measurements:
  - `height_ft`: decimal(6,2), nullable
  - `length_ft`: decimal(7,2), nullable
  - `speed_mph`: decimal(5,2), nullable
  - `max_drop_height_ft`: decimal(6,2), nullable
- Track details:
  - `inversions`: unsigned integer, default 0
  - `ride_time_seconds`: unsigned integer, nullable
  - `track_type`: string, default empty
  - `track_material`: string(20), using TrackMaterial enum
  - `roller_coaster_type`: string(20), using RollerCoasterType enum
- Train configuration:
  - `launch_type`: string(20), using LaunchType enum
  - `train_style`: string, default empty
  - `trains_count`: unsigned integer, nullable
  - `cars_per_train`: unsigned integer, nullable
  - `seats_per_car`: unsigned integer, nullable
- Indexes:
  - track_material
  - roller_coaster_type
  - launch_type

## Design Decisions
1. Used one-to-one relationship for roller_coaster_stats to ensure data integrity
2. Added proper indexes for common query patterns
3. Implemented nullable relationships where appropriate
4. Used appropriate data types for numeric values:
   - decimals for measurements that need precision
   - integers for whole number counts
5. Added proper cascading rules:
   - rides cascade delete with park
   - roller_coaster_stats cascade with ride
   - other relationships set to nullOnDelete for safety

## Migration Order
The migrations are ordered to respect foreign key constraints:
1. ride_models (depends on manufacturers)
2. rides (depends on parks, park_areas, manufacturers, designers, ride_models)
3. roller_coaster_stats (depends on rides)

## Related Files
- Enum classes in app/Enums/
- Model classes (to be implemented)
- Feature documentation in memory-bank/features/RidesManagement.md