Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 28, 2025

This PR migrates ScheduledShow image attachments from Paperclip to Active Storage while preserving all legacy data and maintaining complete backward compatibility.

Overview

The migration adds Active Storage support alongside existing Paperclip functionality, enabling new uploads to use modern Active Storage while keeping all existing Paperclip images accessible. This is a zero-downtime migration that doesn't break any existing functionality.

Key Changes

Model Updates (app/models/scheduled_show.rb)

  • Added has_one_attached :active_storage_image alongside existing Paperclip configuration
  • Implemented intelligent fallback methods for image_url and thumb_image_url that prefer Active Storage but fall back to Paperclip
  • Preserved all existing Paperclip configuration and validations

Controller Enhancements

Updated both scheduled_shows_controller.rb and api/my_shows/episodes_controller.rb to:

  • Detect Active Storage signed IDs vs legacy Paperclip data URIs automatically
  • Handle new uploads with Active Storage while maintaining Paperclip support for existing workflows

Serializer Updates (app/serializers/scheduled_show_serializer.rb)

  • Modified to use the model's new fallback methods transparently
  • API responses remain identical - no breaking changes for consumers

Migration Strategy

Safe Migration Script

Includes a comprehensive migration script at script/migrate_scheduled_show_paperclip_to_active_storage.rb with:

  • Dry-run mode by default for safety
  • Batch processing to handle large datasets
  • Comprehensive error handling and progress reporting
  • Preserves all original Paperclip data - nothing is deleted

Usage Example

# Test the migration safely
RAILS_ENV=production bundle exec ruby script/migrate_scheduled_show_paperclip_to_active_storage.rb

# Run the actual migration
RAILS_ENV=production DRY_RUN=false bundle exec ruby script/migrate_scheduled_show_paperclip_to_active_storage.rb

Backward Compatibility

The implementation ensures complete backward compatibility:

  • All existing Paperclip images continue to work unchanged
  • API responses remain identical
  • Existing upload workflows continue to function
  • No database schema changes required

Testing & Documentation

  • Added comprehensive test suite covering all migration scenarios
  • Included demo script to verify functionality
  • Complete migration documentation with deployment strategy
  • Enhanced controller validation for Active Storage signed IDs

Benefits

  • Zero Downtime: Can be deployed without breaking existing functionality
  • Future-Ready: New uploads use modern Active Storage infrastructure
  • Gradual Migration: Can migrate legacy data at your own pace
  • Safe: Comprehensive error handling and rollback capabilities
  • Transparent: No API changes - completely transparent to consumers

This migration positions the application for future Active Storage benefits while maintaining complete compatibility with existing data and workflows.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)
  • s3.amazonaws.com
    • Triggering command: /usr/bin/ruby3.2 -I/usr/lib/ruby/vendor_ruby extconf.rb (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

This pull request was created as a result of the following prompt from Copilot chat.

Migrate ScheduledShow image attachments from Paperclip to Active Storage, preserving all legacy data.

  • Add has_one_attached :image to ScheduledShow model.
  • Update controller logic to use Active Storage for new uploads.
  • Update serializers to prefer Active Storage images, fallback to Paperclip if not present.
  • Add a script to scripts/migrate_scheduled_show_paperclip_to_active_storage.rb that copies Paperclip images to Active Storage for scheduled shows that have a Paperclip image but no Active Storage image attached.
  • Do not remove any Paperclip configuration, columns, or files. All legacy data is retained.
  • Add instructions for running the script in the script file header.

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits August 28, 2025 18:52
…migration script

Co-authored-by: mcfiredrill <66243+mcfiredrill@users.noreply.github.com>
…d documentation

Co-authored-by: mcfiredrill <66243+mcfiredrill@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate ScheduledShow images from Paperclip to Active Storage with migration script Migrate ScheduledShow image attachments from Paperclip to Active Storage with backward compatibility Aug 28, 2025
Copilot AI requested a review from mcfiredrill August 28, 2025 18:56
belongs_to :recording

# Active Storage attachment for new images
has_one_attached :active_storage_image
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
has_one_attached :active_storage_image
has_one_attached :as_image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants