Current section: Real World Examples 15 exercises

Realistic Database Seeding with AI

Imagine you need to seed a database with test data that is realistic.

Instead of coming up with each unique item manually, or using 'lorem ipsum' everywhere, your AI assistant can help you generate realistic data.

By writing a comment inside of your database seeding script, GitHub Copilot will be

Loading lesson


00:00 Another thing that your AI assistant is really good at, at helping you with, is creating fake data. So I've got this seed script for seeding our Epic Stack database with a bunch of users and notes and passwords, connections, all of this stuff. And I want to have a specific user that I can always log in

00:18 and he always has these specific notes and everything. That's kind of what a seed script is for. So, but I don't want to have to like come up with reasonable notes. And I don't want to also do like lorem ipsum everywhere, like I'm sick and tired of seeing UIs or lorem ipsum. I want something that's like a little more realistic, please.

00:37 And so our AI assistant can help us with that. But something that is really useful for the AI assistant is to see an example. And so while we do have some stuff up here, that's kind of an example of what it takes to create a note, this is the lorem ipsum stuff. Right here, we're going to have it create some like actual useful content.

00:57 So I'm going to add a comment so that AI is aware of what I'm going for here by saying, create a bunch of notes that do not use lorem ipsum. Thank you, co-pilot. Okay, so we'll say ID.

01:13 And actually let's also say with hard coded IDs. Okay, there we go. So yeah, sure, mock code note one, that works. Yeah, that's fine. The thing is that's going to show up in the URL. It's going to be kind of annoying.

01:29 So let's just like ABC123, that works. Title, welcome to Notedly. Yeah, sure, that's fine. Content, this is a note. Yeah, that like, that's boring. Come on, co-pilot, let's do a command I on this and let's actually make the title better.

01:49 Fun facts about koalas. There we go. And then let's update this. Update this note content to be fun facts about koalas. And here we go. Fun facts about koalas.

02:05 Oh, to be or be more realistic based on the title. There we go. Try that. Do koalas are recipials? Yeah, now we're talking. Okay, good, good.

02:24 Let's say make it multiline with tagged template. Actually, you know what? I don't want it to be multiline. That's fine, let's accept it. 'Cause like stuff like this, I don't need to be able to read it. It just needs to be there as the generated stuff. Okay, awesome.

02:41 So now we have an example of what we're going for. So co-pilot should be able to create a bunch more of these and it should auto-complete some of these once we get our cursor in the right position. Sometimes I notice that it actually doesn't. And so in these cases, bringing up the chat and saying,

02:59 create another three of these fake hard-coded notes. And from here, it will just go ahead and create all of those for us. Entering facts about penguins and elephants. It's very serious about these examples.

03:18 Here, let's say they don't all have to be here. They don't all have to be about, or interesting facts about animals. Be more creative, AI. I know they're not supposed to be able to be creative, but this is what we're gonna do.

03:37 The art of origami, the magic of music, wonders of astronomy. I love it, love it. That's awesome, let's accept all those. And the current state of the art with co-pilot is it totally doesn't know how to do braces and quotes and everything. So I do find myself cleaning this stuff up quite a lot,

03:57 which is super duper annoying, but it is what it is. It's worth it anyway. Okay, here we are, something like this. Get rid of that, boom. And then we think our lucky stars are prettier 'cause it can fix all this nonsense. Great, so that is creating a bunch of fake data with our assistant.

04:17 That is a little bit more interesting and just follows the example of previous data. Now, being inside of this file might have made some of this a little bit more tricky. So if you were just like, I wanna create a whole bunch of data, then you could open up the chat just by saying,

04:35 create a bunch of examples of notes that have a hard-coded ID, title, and content. Yeah, based on various subjects and serialized as JSON.

04:50 There we go. And right here, we can ask Copilot to do that. So we'll do that and it'll pop open the Copilot chat right here. And now here we have it generating all of those for us.

05:09 So we've got the wonders of space and it's probably actually using some of this as inspiration for what it's doing in here as well, which is nice. So we're getting those like three letters, three numbers as kind of the following the pattern that we had in here, which is totally fine. And then we can actually just take this right here

05:29 and say, hey, insert that, boom. And now it's right there. We can clean up this and add a comma and boom, we've got a bunch more. So using a combination of like right in line and off to the side can help keep the chat that you are having with Copilot conversational

05:49 so that you can make fine-tuned suggestions to the AI so it can produce exactly what you're looking for. And this is the sort of thing I do all the time. It saves me a ton of time. So there you go. That is creating data with your AI assistant.