Current section: Generating Seed Data 5 exercises

Intro to Generating Seed Data


00:00 I don't know about you, but I don't want to have to create every single user that I want in my database, every single hard code, all of that data. That just doesn't sound fun to me at all. And so you'd end up with a seed file that was enormous. And what if you wanted to do some performance testing?

00:19 So you want to create 6,000 users or something like that. Yeah, that would be awful. And so we're going to randomly create some data. You create some fake data using a library called Faker. So if you've never used it before, this kind of gives you an idea of what you can do with Faker. It's pretty cool. It comes from their docs.

00:37 And yeah, you can also generate a fake number of things. And so here you can create a number between 1 and 10 and then create an array out of those things, which is pretty cool. And then we also are going to be using a unique enforcer.

00:54 This is a utility that allows you to just ensure that you only create the same value once. So you don't end up with two usernames that are exactly the same when we're supposed to be doing unique usernames, for example, which is our example.

01:13 And then we've got another important aspect of generating this fake data is sometimes the fake data generates it to be too long for what we validate. So our usernames are only 20 characters long. So if it creates some fake data that's longer than that, then we're going to be in a bit of trouble.

01:30 So we're going to also be adding a little bit of stuff to these utilities to make sure that they don't generate something that's outside of our validation logic. So you've got some work to do, and this is going to be awesome. Once we're done with this, our seed data generator is going to be awesome.

01:49 So have a good time, and we'll see you when you're done.