How to migrate to Active Storage without losing your mind

Ee5d925e923e9312b8633b75effcbfdb?s=47 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.

Ee5d925e923e9312b8633b75effcbfdb?s=128

Colleen

May 02, 2019
Tweet

Transcript

  1. Bitmapped Designs Colleen Schnettler Bitmapped Designs LLC www.bitmappeddesigns.com Bitmapped Designs

    How to Migrate To Active Storage Without losing your mind
  2. @leenyburger Bitmapped Designs www.bitmappeddesigns.com A story… Fun Startup Rails Developer

    Migrate to Active Storage Start of a beautiful contract relationship!
  3. @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
  4. @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
  5. @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:
  6. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Implementing Active Storage in a new

    application is EASY
  7. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Migrating to Active Storage is hard.

  8. @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)
  9. @leenyburger Bitmapped Designs www.bitmappeddesigns.com User table schema is changed ernie-avatar.jpg

  10. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage is different Active Storage

    creates 2 new tables 1. Active Storage Attachments 2. Active Storage Blobs
  11. @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:
  12. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Create Active Storage Tables

  13. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Configure Cloud Storage

  14. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Configure Cloud Storage

  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:
  16. @leenyburger Bitmapped Designs www.bitmappeddesigns.com A rake task!

  17. @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
  18. @leenyburger Bitmapped Designs www.bitmappeddesigns.com User table schema is changed ernie-avatar.jpg

  19. @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
  20. But Wait?!

  21. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage Attachments Table

  22. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage Attachments Table

  23. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage Attachments Table

  24. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage BLOBS Table

  25. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage BLOBS Table

  26. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage BLOBS Table

  27. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage BLOBS Table

  28. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Table mapping

  29. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Table mapping

  30. @leenyburger Bitmapped Designs www.bitmappeddesigns.com A rake task!

  31. Step 1 Reference the Paperclip “Migration" Guide

  32. Step 2

  33. @leenyburger Bitmapped Designs www.bitmappeddesigns.com User table schema is changed ernie-avatar.jpg

  34. Step 2

  35. Step 3 user

  36. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Two deploys required!

  37. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Two deploys? Rake task needs: 1.

    user.avatar relaSonship defined by paperclip 2. AcSve storage tables
  38. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Two deploys? AcUve Storage needs: 1.

    Data in the acSve storage tables
  39. Step 3

  40. Key and Checksum ∑

  41. Step 3

  42. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Run Rake Task Records created? AcSveStorage::Blob.count

    AcSveStorage::AWachment.count
  43. 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
  44. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Make and checkout a new branch

    No really. Do it.
  45. @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
  46. Update Views, Models, Controllers and Tests Models: Views:

  47. @leenyburger Bitmapped Designs www.bitmappeddesigns.com What are variants? No image processing!

    Paperclip Active Storage
  48. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Too early to the party? 6

    To save the day!
  49. @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
  50. @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:
  51. @leenyburger Bitmapped Designs www.bitmappeddesigns.com Congrats!