Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
How to migrate to Active Storage without losing your mind
Colleen
May 02, 2019
Technology
0
1.8k
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
Share
More Decks by Colleen
See All by Colleen
colleen711
0
40
Other Decks in Technology
See All in Technology
sylph01
0
170
clustervr
0
160
tsuyo
0
180
yokatsuki
1
190
pinboro
1
1.5k
yasuakiomokawa
0
330
comucal
PRO
0
410
kaga
0
190
kurotanshi
0
170
yuuturn
1
130
greymd
0
600
yuyaabo
0
250
Featured
See All Featured
cassininazir
347
20k
jeffersonlam
328
15k
ammeep
656
54k
carmenhchung
26
1.3k
danielanewman
1
470
destraynor
223
47k
brettharned
93
3k
ddemaree
274
31k
shlominoach
176
7.4k
morganepeng
17
1.1k
rocio
155
11k
kneath
219
15k
Transcript
Bitmapped Designs Colleen Schnettler Bitmapped Designs LLC www.bitmappeddesigns.com Bitmapped Designs
How to Migrate To Active Storage Without losing your mind
@leenyburger Bitmapped Designs www.bitmappeddesigns.com A story… Fun Startup Rails Developer
Migrate to Active Storage Start of a beautiful contract relationship!
@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
@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
@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:
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Implementing Active Storage in a new
application is EASY
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Migrating to Active Storage is hard.
@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)
@leenyburger Bitmapped Designs www.bitmappeddesigns.com User table schema is changed ernie-avatar.jpg
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage is different Active Storage
creates 2 new tables 1. Active Storage Attachments 2. Active Storage Blobs
@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:
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Create Active Storage Tables
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Configure Cloud Storage
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Configure Cloud Storage
@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:
@leenyburger Bitmapped Designs www.bitmappeddesigns.com A rake task!
@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
@leenyburger Bitmapped Designs www.bitmappeddesigns.com User table schema is changed ernie-avatar.jpg
@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
But Wait?!
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage Attachments Table
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage Attachments Table
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage Attachments Table
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage BLOBS Table
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage BLOBS Table
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage BLOBS Table
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Active Storage BLOBS Table
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Table mapping
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Table mapping
@leenyburger Bitmapped Designs www.bitmappeddesigns.com A rake task!
Step 1 Reference the Paperclip “Migration" Guide
Step 2
@leenyburger Bitmapped Designs www.bitmappeddesigns.com User table schema is changed ernie-avatar.jpg
Step 2
Step 3 user
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Two deploys required!
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Two deploys? Rake task needs: 1.
user.avatar relaSonship defined by paperclip 2. AcSve storage tables
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Two deploys? AcUve Storage needs: 1.
Data in the acSve storage tables
Step 3
Key and Checksum ∑
Step 3
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Run Rake Task Records created? AcSveStorage::Blob.count
AcSveStorage::AWachment.count
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
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Make and checkout a new branch
No really. Do it.
@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
Update Views, Models, Controllers and Tests Models: Views:
@leenyburger Bitmapped Designs www.bitmappeddesigns.com What are variants? No image processing!
Paperclip Active Storage
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Too early to the party? 6
To save the day!
@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
@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:
@leenyburger Bitmapped Designs www.bitmappeddesigns.com Congrats!