# Phase 009 Execution ## Scope - Add image attachments for fuel and maintenance entries. - Keep vehicle history image loading explicit and lightweight. - Extend backups with data-only and image-inclusive options. ## Changes - Installed Active Storage tables. - Added `has_many_attached :images` to fuel and maintenance entries. - Added shared image validation for JPEG/PNG-only uploads with a 10 MB per-image limit. - Added multi-file image upload fields to fuel and maintenance entry forms. - Added lazy inline image endpoints for fuel and maintenance history rows. - Added hidden inline upload forms for adding images to existing fuel and maintenance entries. - Successful existing-entry image uploads immediately render the thumbnail/delete UI. - Invalid existing-entry image uploads keep the inline form visible and purge the rejected files. - Added small thumbnail rendering with links to full-size images. - Added delete actions for individual fuel and maintenance entry images. - Added data-only and image-inclusive backup download options. - Bumped backup exports to version 2. - Preserved version 1 backup import support as data-only imports. - Added image export/import using Base64-encoded image data in gzip-compressed YAML. - Added merge-import image deduplication by filename and checksum. - Added replace-mode image purging before direct app-data deletion. - Added model and request specs for upload validation, lazy loading, deletion, backup export, restore, and deduplication. - Added request specs for loading existing-entry upload forms and attaching images to previous fuel and maintenance entries. - Fixed existing-entry image uploads so they validate only newly uploaded images instead of rerunning all historical entry validations. - Filtered blank file-field values from existing-entry image uploads. - Added regression coverage for adding images to old fuel entries whose odometer is now lower than the vehicle current odometer. - Changed inline image thumbnails to use original blob URLs instead of Active Storage variants so thumbnails do not require server-side image processing libraries. - Added per-entry duplicate image detection by checksum for new entry creation and existing-entry image uploads. - Added a user-facing duplicate error: `This image is already attached to this entry`. - Preserved the ability to attach the same image to different entries. ## Decisions - Images are stored with Active Storage. - Fuel and maintenance entries support multiple images. - Only JPEG and PNG uploads are accepted. - Each image is limited to 10 MB. - History images load inline only when requested. - Full-size images open from thumbnail links. - Backups keep gzip-compressed YAML and offer separate data-only and image-inclusive downloads. ## Verification - Passed: `bundle exec rspec spec/models/fuel_entry_spec.rb spec/models/maintenance_entry_spec.rb spec/requests/vehicles_spec.rb spec/requests/backups_spec.rb` - Passed: `bundle exec rspec` - Passed: `bin/rubocop app/models/concerns/entry_image_validation.rb app/models/fuel_entry.rb app/models/maintenance_entry.rb app/controllers/fuel_entries_controller.rb app/controllers/maintenance_entries_controller.rb app/controllers/fuel_entry_images_controller.rb app/controllers/maintenance_entry_images_controller.rb app/controllers/backups_controller.rb app/controllers/vehicles_controller.rb app/services/backup_export.rb app/services/backup_import.rb spec/models/fuel_entry_spec.rb spec/models/maintenance_entry_spec.rb spec/requests/vehicles_spec.rb spec/requests/backups_spec.rb` - Passed: `bin/ci` - Passed after existing-entry upload support: `bundle exec rspec spec/requests/vehicles_spec.rb` - Passed after existing-entry upload support: `bundle exec rspec spec/requests/vehicles_spec.rb spec/requests/backups_spec.rb spec/models/fuel_entry_spec.rb spec/models/maintenance_entry_spec.rb` - Passed after existing-entry upload support: `bundle exec rspec` - Passed after existing-entry upload support: `bin/rubocop app/controllers/fuel_entries_controller.rb app/controllers/maintenance_entries_controller.rb app/controllers/fuel_entry_images_controller.rb app/controllers/maintenance_entry_images_controller.rb spec/requests/vehicles_spec.rb` - Passed after existing-entry upload support: `bin/ci` - Passed after historical-entry upload fix: `bundle exec rspec spec/requests/vehicles_spec.rb` - Passed after historical-entry upload fix: `bundle exec rspec spec/requests/vehicles_spec.rb spec/requests/backups_spec.rb spec/models/fuel_entry_spec.rb spec/models/maintenance_entry_spec.rb` - Passed after historical-entry upload fix: `bundle exec rspec` - Passed after historical-entry upload fix: `bin/rubocop app/controllers/fuel_entries_controller.rb app/controllers/maintenance_entries_controller.rb spec/requests/vehicles_spec.rb` - Passed after historical-entry upload fix: `bin/ci` - Passed after thumbnail and duplicate-image fix: `bundle exec rspec spec/requests/vehicles_spec.rb` - Passed after thumbnail and duplicate-image fix: `bundle exec rspec spec/requests/vehicles_spec.rb spec/requests/backups_spec.rb spec/models/fuel_entry_spec.rb spec/models/maintenance_entry_spec.rb` - Passed after thumbnail and duplicate-image fix: `bundle exec rspec` - Passed after thumbnail and duplicate-image fix: `bin/rubocop app/controllers/fuel_entries_controller.rb app/controllers/maintenance_entries_controller.rb app/models/concerns/entry_image_validation.rb spec/requests/vehicles_spec.rb spec/models/fuel_entry_spec.rb spec/models/maintenance_entry_spec.rb` - Passed after thumbnail and duplicate-image fix: `bin/ci`