mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 17:31:13 -05:00
Fix ride submission data loss
Implement the plan to fix critical data loss in ride submissions. This includes: - Storing ride technical specifications, coaster statistics, and name history in submission tables. - Adding missing category-specific fields to the `ride_submissions` table via a new migration. - Updating submission helpers and the edge function to include these new fields. - Fixing the park location Zod schema to include `street_address`.
This commit is contained in:
@@ -1177,13 +1177,109 @@ export async function submitRideCreation(
|
||||
banner_image_id: bannerImage?.cloudflare_id || data.banner_image_id || null,
|
||||
card_image_url: cardImage?.url || data.card_image_url || null,
|
||||
card_image_id: cardImage?.cloudflare_id || data.card_image_id || null,
|
||||
image_url: null
|
||||
image_url: null,
|
||||
// Category-specific fields
|
||||
track_material: (data as any).track_material || null,
|
||||
support_material: (data as any).support_material || null,
|
||||
propulsion_method: (data as any).propulsion_method || null,
|
||||
water_depth_cm: (data as any).water_depth_cm || null,
|
||||
splash_height_meters: (data as any).splash_height_meters || null,
|
||||
wetness_level: (data as any).wetness_level || null,
|
||||
flume_type: (data as any).flume_type || null,
|
||||
boat_capacity: (data as any).boat_capacity || null,
|
||||
theme_name: (data as any).theme_name || null,
|
||||
story_description: (data as any).story_description || null,
|
||||
show_duration_seconds: (data as any).show_duration_seconds || null,
|
||||
animatronics_count: (data as any).animatronics_count || null,
|
||||
projection_type: (data as any).projection_type || null,
|
||||
ride_system: (data as any).ride_system || null,
|
||||
scenes_count: (data as any).scenes_count || null,
|
||||
rotation_type: (data as any).rotation_type || null,
|
||||
motion_pattern: (data as any).motion_pattern || null,
|
||||
platform_count: (data as any).platform_count || null,
|
||||
swing_angle_degrees: (data as any).swing_angle_degrees || null,
|
||||
rotation_speed_rpm: (data as any).rotation_speed_rpm || null,
|
||||
arm_length_meters: (data as any).arm_length_meters || null,
|
||||
max_height_reached_meters: (data as any).max_height_reached_meters || null,
|
||||
min_age: (data as any).min_age || null,
|
||||
max_age: (data as any).max_age || null,
|
||||
educational_theme: (data as any).educational_theme || null,
|
||||
character_theme: (data as any).character_theme || null,
|
||||
transport_type: (data as any).transport_type || null,
|
||||
route_length_meters: (data as any).route_length_meters || null,
|
||||
stations_count: (data as any).stations_count || null,
|
||||
vehicle_capacity: (data as any).vehicle_capacity || null,
|
||||
vehicles_count: (data as any).vehicles_count || null,
|
||||
round_trip_duration_seconds: (data as any).round_trip_duration_seconds || null
|
||||
} as any)
|
||||
.select('id')
|
||||
.single();
|
||||
|
||||
if (rideSubmissionError) throw rideSubmissionError;
|
||||
|
||||
// Insert technical specifications if present
|
||||
if ((data as any)._technical_specifications?.length > 0) {
|
||||
const { error: techSpecError } = await supabase
|
||||
.from('ride_technical_specs' as any)
|
||||
.insert(
|
||||
(data as any)._technical_specifications.map((spec: any) => ({
|
||||
ride_submission_id: (rideSubmission as any).id,
|
||||
spec_name: spec.spec_name,
|
||||
spec_value: spec.spec_value,
|
||||
spec_type: spec.spec_type,
|
||||
category: spec.category || null,
|
||||
unit: spec.unit || null
|
||||
}))
|
||||
);
|
||||
|
||||
if (techSpecError) {
|
||||
logger.error('Failed to insert technical specs', { error: techSpecError });
|
||||
throw techSpecError;
|
||||
}
|
||||
}
|
||||
|
||||
// Insert coaster statistics if present
|
||||
if ((data as any)._coaster_statistics?.length > 0) {
|
||||
const { error: statsError } = await supabase
|
||||
.from('ride_coaster_stats' as any)
|
||||
.insert(
|
||||
(data as any)._coaster_statistics.map((stat: any) => ({
|
||||
ride_submission_id: (rideSubmission as any).id,
|
||||
stat_name: stat.stat_name,
|
||||
stat_value: stat.stat_value,
|
||||
unit: stat.unit || null,
|
||||
category: stat.category || null
|
||||
}))
|
||||
);
|
||||
|
||||
if (statsError) {
|
||||
logger.error('Failed to insert coaster stats', { error: statsError });
|
||||
throw statsError;
|
||||
}
|
||||
}
|
||||
|
||||
// Insert name history if present
|
||||
if ((data as any)._name_history?.length > 0) {
|
||||
const { error: historyError } = await supabase
|
||||
.from('ride_name_history_submissions' as any)
|
||||
.insert(
|
||||
(data as any)._name_history.map((name: any) => ({
|
||||
ride_submission_id: (rideSubmission as any).id,
|
||||
former_name: name.former_name,
|
||||
date_changed: name.date_changed ? new Date(name.date_changed).toISOString().split('T')[0] : null,
|
||||
reason: name.reason || null,
|
||||
from_year: name.from_year || null,
|
||||
to_year: name.to_year || null,
|
||||
order_index: name.order_index || 0
|
||||
}))
|
||||
);
|
||||
|
||||
if (historyError) {
|
||||
logger.error('Failed to insert name history', { error: historyError });
|
||||
throw historyError;
|
||||
}
|
||||
}
|
||||
|
||||
// Create submission_items record linking to ride_submissions
|
||||
const { error: itemError } = await supabase
|
||||
.from('submission_items')
|
||||
|
||||
Reference in New Issue
Block a user