Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to migrate to Active Storage without losing your mind

Colleen
May 02, 2019

How to migrate to Active Storage without losing your mind

A talk on migrating from paperclip to active storage, common pitfalls, and lessons learned.

Colleen

May 02, 2019
Tweet

More Decks by Colleen

Other Decks in Technology

Transcript

  1. @leenyburger Bitmapped Designs www.bitmappeddesigns.com A story… Fun Startup Rails Developer

    Migrate to Active Storage Start of a beautiful contract relationship!
  2. @leenyburger Bitmapped Designs www.bitmappeddesigns.com What is Active Storage? Active Storage

    is an easy way to attach files to Active Record objects and store those files in cloud based storage. S3 User Avatar
  3. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Why Active Storage? Paperclip is deprecated

    No additional migrations Built in solution for handing file uploads to cloud storage Supports: Amazon S3, Google Cloud Storage, Microsoft Azure
  4. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage Documents Install Active Storage

    Step 1: Step 4: Configure Cloud Storage Step 2: Add an attachment to a model Step 3:
  5. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Why? Active Storage is fundamentally different

    from paperclip. Paperclip works by attaching file data to the model Avatar added to User table Avatar User (Ernie)
  6. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage is different Active Storage

    creates 2 new tables 1. Active Storage Attachments 2. Active Storage Blobs
  7. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage Documents Install Active Storage

    Step 1: Step 4: Configure Cloud Storage Step 2: Add an attachment to a model Step 3:
  8. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage Documents Install Active Storage

    Step 1: Step 4: Configure Cloud Storage Step 2: Move avatar data from User table to Active Storage Tables Step 3:
  9. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Map attachment data FROM the Users

    table TO Active Storage Tables Users Table Active Storage Attachments Active Storage Blobs
  10. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Map attachment data FROM the Users

    table TO Active Storage Tables Users Table Active Storage Attachments Active Storage Blobs
  11. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Two deploys? Rake task needs: 1.

    user.avatar relaSonship defined by paperclip 2. AcSve storage tables
  12. What we’ve done 2. Configured AcSve Storage Cloud Storage 1.

    Created the AcSve Storage Tables 3. WriWen a rake task to create User Avatar records in the AWachments and Blobs tables 4. Confirmed records were created in the AcSve Storage Tables
  13. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Deploy Deploy with paperclip, rake task,

    and active storage tables Deploy with Active Storage models/views S3 dev_bucket 1. Run rake task
  14. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Deploy Deploy with paperclip, rake task,

    and active storage tables Deploy with Active Storage models/views S3 dev_bucket
  15. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage Documents Install Active Storage

    Step 1: Step 4: Configure Cloud Storage Step 2: Move avatar data from User table to Active Storage Tables Step 3: