church-api/fix_image_path.fish
Benjamin Slingo 0c06e159bb Initial commit: Church API Rust implementation
Complete church management system with bulletin management, media processing, live streaming integration, and web interface. Includes authentication, email notifications, database migrations, and comprehensive test suite.
2025-08-19 20:56:41 -04:00

75 lines
3.1 KiB
Fish
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env fish
echo "🔧 COMPLETE IMAGE_PATH FIX (v5 - SUBMISSION + UPDATES)"
echo "====================================================="
# Restore from backups first
if test -f "src/models.rs.backup2"
cp src/models.rs.backup2 src/models.rs
cp src/db/events.rs.backup2 src/db/events.rs
cp src/handlers/events.rs.backup2 src/handlers/events.rs
echo "✅ Restored from backups"
end
echo "1⃣ Adding image_path to BOTH CreateEventRequest AND SubmitEventRequest..."
# Add to CreateEventRequest
sed -i '/pub struct CreateEventRequest {/,/^}/ {
/pub recurring_type: Option<String>,/ a\
pub image_path: Option<String>,
}' src/models.rs
# Add to SubmitEventRequest
sed -i '/pub struct SubmitEventRequest {/,/^}/ {
/pub submitter_email: Option<String>,/ a\
pub image_path: Option<String>,
}' src/models.rs
echo "2⃣ Adding image_path to SubmitEventRequest initialization in handlers..."
sed -i '/let mut req = SubmitEventRequest {/,/};/ {
/submitter_email: None,/ a\
image_path: None,
}' src/handlers/events.rs
echo "3⃣ Fixing the submit_for_approval function SQL..."
# Update the INSERT statement to include image_path
sed -i 's|category, is_featured, recurring_type, bulletin_week, submitter_email|category, is_featured, recurring_type, bulletin_week, submitter_email, image_path|' src/db/events.rs
sed -i 's|VALUES (\$1, \$2, \$3, \$4, \$5, \$6, \$7, \$8, \$9, \$10, \$11)|VALUES (\$1, \$2, \$3, \$4, \$5, \$6, \$7, \$8, \$9, \$10, \$11, \$12)|' src/db/events.rs
echo "4⃣ Fixing the events table update function..."
sed -i 's|recurring_type = \$9, updated_at = NOW()|recurring_type = \$9, image_path = \$10, updated_at = NOW()|' src/db/events.rs
sed -i 's|WHERE id = \$10|WHERE id = \$11|' src/db/events.rs
sed -i '/req\.recurring_type,$/a\ req.image_path,' src/db/events.rs
echo "5⃣ Building..."
if cargo build
echo "✅ SUCCESS! Both submission and updates now support image_path."
echo ""
echo "=== What was fixed ==="
echo "✅ Added image_path to CreateEventRequest struct (for updates)"
echo "✅ Added image_path to SubmitEventRequest struct (for new submissions)"
echo "✅ Updated handlers to initialize image_path field"
echo "✅ Fixed submit_for_approval SQL to include image_path column"
echo "✅ Fixed update SQL to include image_path column"
echo ""
echo "🚀 Next steps:"
echo "1. Restart your API server"
echo "2. Run your image_path update script"
echo "3. Both new submissions AND existing event updates will handle image_path!"
else
echo "❌ Build failed. Let's debug..."
echo ""
echo "=== Current structs ==="
grep -A 15 "pub struct CreateEventRequest" src/models.rs
echo ""
grep -A 15 "pub struct SubmitEventRequest" src/models.rs
echo ""
echo "=== Current submit_for_approval function ==="
grep -A 15 "submit_for_approval.*SubmitEventRequest" src/db/events.rs
# Restore
cp src/models.rs.backup2 src/models.rs
cp src/db/events.rs.backup2 src/db/events.rs
cp src/handlers/events.rs.backup2 src/handlers/events.rs
echo "🔄 Restored backups"
end