Seeding Your Phoenix App Database with Random Users

Today, I stumbled upon some rant about how people are hating Ruby on Rails and are giving up. I want to avoid such drama, and I am not exactly one of those who stopped using Ruby on Rails. I still use Ruby on Rails, and teach it every week in fact. I teach people with ambition, and it sort of awakened my lazy self to pursue more challenging work. If beginners are already doing challenging work, why am I not doing more of that?

WIP micro-social network built with Phoenix framework, React.js and Redux

The weekly open source challenge

All rants are valid. People who have done a lot, especially for the open source community, will experience some kind of fatigue. And a realization that their golden tools and frameworks aren’t so golden sort of heightens the feeling they have wasted their time. Well, if you feel the same way because you invested so much time in the OOP world and suddenly feel like a turtle compared to everyone else, just keep calm and learn everything. I am certain Ruby on Rails is still a good framework.

In the future, expect that I might write more about Elixir than Ruby and JavaScript. It’s a matter of need, rather than interest. I find all languages interesting. I even like C#, but I am not a game developer. I really want to be a game developer, but I have to learn so much. I have a business background, and been so focused on e-commerce applications for years.

If you haven’t tried Phoenix framework yet, you should. I don’t like to talk about inefficiencies of a certain framework compared to Phoenix. The real world needs all these frameworks. It’s just that our reality didn’t meet our expectations, and we all dealt with monolithic applications that are challenging to maintain. What I’m most certain about: Elixir and Phoenix can do whatever your favorite language and framework can do today.

The primary roadblock is the small Elixir community, and people are contributing less to open source. I try to release as many packages on despite being a beginner. I don’t have a year experience in Elixir or Phoenix, but I am very experienced as Ruby on Rails developer. There are a lot of similarities.

Recently I have been building a micro-social network that uses it. I do everything from React.js to Elixir work. It’s far from done, but I would likely ship this. Yes, I actually have Ruby on Rails apps that I killed but have started rewriting them to use Phoenix instead. These were started ages ago. OK, not ages. About 2014 or so. In the software world, 2 years feels like lightyears. Everything is changing quickly. You need a bullet train to get somewhere, and a sponge-like ability to absorb data quickly. Like many, I have the fear of being left out. But more than that, I am really obsessed about technologies optimized for better user experience.

Seeding your database with random users

If you’ve spent some time checking your available options for seeding the database, you probably know about faker and for most cases, it is sufficient. Except, when you need to do a demo and make sure it is populated with data which looks closer to real.

Thanks to, it is possible to populate the database the way I wanted it to.

I have published random_user today. I think it’s efficient. To populate a users table with 500 users, you only need a few lines of code.

users = RandomUser.Random.multiple(500) |> RandomUser.Parser.results

We use Enum which is very much like Ruby Enumerable., fn u ->
  user = u |> RandomUser.Parser.parse
  large_pic = user.picture["large"]

My experience with writing that package was pleasant because of exVCR project. It is an excellent way to test apps that consume API’s.

Further Reading

  1. Random User
  2. Faker
  3. exVCR