Loading
Current section: Generating Seed Data 5 exercises
Problem

Creating Unique User Data with Enforce Unique Library

Transcript

00:00 You know how we have a unique constraint on both the username and email? This is very good. It will help our queries to email and username be a lot faster. And just like from a pure product standpoint, it makes a lot of sense for those things to be unique. In fact, we're going to log the user in with their username or email as well. So we need to have those be unique.

00:19 The problem is in our seed data, we're not actually generating unique values quite yet. Like we're generating random values, and it's possible that two of these users could end up with the same unique value for the username and first name and last name and email and all that. It's unlikely, but definitely possible. It can happen.

00:37 So I want you to update this create user utility so that it ensures that that is unique, at least in the process of running the seed, and that will reduce the chance of collisions. So we've got a library that we're going to use called Enforce Unique.

00:55 So give that a look. And yeah, let's get this implemented so we don't run into some collisions. Have a good time.