00:09
and let's just call this our initial cedar. Okay. We have a file for that created now within our database directory.
00:16
So let's go into there, our cedars and there is our initial cedar. The only goal that we have with the cedar is to get our roles up and create it.
00:24
So if you created a role model, then we can go ahead and use that to create these. So a weight role, import that model that it will just call, create many, which allows
00:34
us to provide an array with each of the models that we want to create. So first we're going to want a model for our members. These are just organization members.
00:43
They'll have the base level of access for an organization. Then we're also going to want an administrator. So we'll add a name here and we'll just call these admin to ease our burden of checking
00:53
what role a user is. Let's also give these forced IDs so that we can map those IDs to an enum as well.
01:01
So let's come in here and add in an ID column. And for example, let's say our members are one and our admins are two.
01:08
And to ensure that our IDs here match against our enums, let's go ahead and use the enum itself to set the ID value.
01:14
So let's create inside of our app directory, a new folder called enums and inside of it, create a file called roles.ds.
01:22
Inside of here, we'll define an enum called roles with a member and a value of one and an admin with a value of two.
01:31
And then we'll go ahead and export default roles. Cool. Jump back now into our initial seeder and then we can just go up to where we have those
01:38
IDs hard set and instead use our roles, import that from our enums.member and we'll pause here for a second. You notice that that did a relative import.
01:48
If you prefer those, that's perfectly fine. If you prefer, however, the hashed imports with a namespace, we can go ahead and scroll
01:54
down to our package.json file and add one of those into our imports object here.
02:01
So we'll just do hash enums slash star and apply the value as dot slash app enums dot slash star dot JS.
02:11
So anytime that we type out hash enums slash whatever, we're telling it to search for that
02:16
file inside of our app directory enums and then any file ending with dot JS there. So with that applied now, let's go back into our initial seeder and we can either adjust
02:26
our import manually or we can just clear it out, go back to our roles, hit command dot and add the import again. All right.
02:34
With that added, we can now do roles dot admin for our admin. And now with this, we've guaranteed that our roles enum member is going to match the ID
02:43
of our actual database members and the same with our admins. If for any reason that ID is already taken, we're going to get an error whenever we attempt to run our seeder. Okay.
02:52
So now we're ready to go ahead and run this seeder. So let's make sure that we have everything saved and then we can open up our terminal and run node ace db colon seed. And there we go.
03:02
It's now completed. So if we do node ace repl await load models and then do models dot role dot all, Oh,
03:12
yep. Got it. We'll wait it. Sorry. Await models dot role dot all. Run that. You'll see that we get back our role here and another role up there.
03:20
Let's go ahead and switch that from doing all to query dot polio so that it returns back just the database results. And there we go.
03:28
Now we can see that we have an ID of one with our members and an ID of two with our admin. Awesome. Dot exit to exit out of that rebel session and we can clear a terminal out and we're now good to go.
03:38
Thanks for watching. Have a great day.