Seed your database with the Faker gem. Then seed 9.4x faster with upsert_all and activerecord-import.

21-Jul-2023 494
I cover 3 things in this article —Using the faker gem in a Rails app to seed 10,000 fake records.Fixing our slow seeds by making them 9.4x faster, using upsert_all or the activerecord-import gem (since our naive method is very inefficient).Finally, I show you how to split your database seeds into 3 separate files — one file for each Rails environment. This way, you won't seed your production database with lots of faker generated records.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle