So how did you make out with the exercise and did you notice that we didn't add any indices to the reservations
table?
Hopefully you did.
If not, don't worry.
I have the solution to the exercise and we'll add a couple of indices to the reservations table as well.
So let's go back to our idea and open a terminal window and clear the screen and create a migration.
So to generate fees, add K and all the indices at the same time indices.
To reservation table that creates the migration's let's open them up, so under Migration's it will
be the bottom two.
And I want to first of all, add a foreign key and I want to add indices.
So let's copy one of our foreign key creations here just to save some typing and paste it in here and
let's copy and indices up so here and paste it in here.
And we'll just put one for now until we decide how many we want to add.
First of all, we're working on the reservations table and we want to add a foreign key from if I go
back to my diagram from reservation ID to reservations.
So it's actually in the room restrictions table.
Let's go back there and fix that.
Room restrictions and its reservation is on the reservations table and its ID, so that will be that.
Now, what indices do we want on the reservations table?
Because we have them here already.
We don't have any on this one.
Well, think about how you might be looking things up.
You're probably going to look for a reservation by last name or email.
So let's go with that on reservations.
We want to add an index to email and we want to add an index on last name.
So what we're doing in one migration is adding a foreign key to the room restrictions table from the
column reservation ID to the reservations table column ID.
And then on the reservations table, we're adding a basic default index, a very fast lookup on email
and on the last name.
So let's run that and see if we got it right.
So to migrate and we did.
But of course we also need the down.
So let's open our down one and let's see how we have a down for foreign keys.
We'll just copy one, we'll copy this one and open up our down again and paste it in.
And we're adding two indices both on the reservations table and it will be for reservations.
We can look the name up, but we figured out the syntax by now.
I'm sure reservations and the link is the foreign key now, the foreign keys on the room restriction
table.
Room restrictions and we're going from room restrictions.
And the column is reservation it, so it'll be reservation idy, and that will drop that and we only
have one for Inchy.
So now let's go to the down for creating indices and there's one we can copy.
So let's copy this one.
And the indices, there are two of them, both on the reservations table.
And one was for reservations.
And it's not remedy.
It was email and we'll just duplicate that and get rid of this one and the other one was for last name
and that's all there is to it.
So now we have our up and down migration's and we've added a couple of indices.
So we're pretty much good to go at this point.
We've actually created our database structure and everything seems to work as expected.
So here's a cool thing.
Watch this.
I'm going to open my terminal window and say SOTA reset.
Now, it's not going to work the first try and I'm going to make it not work on purpose just because
you will do this at some point.
If I try to reset what this is going to do is run all of the down migration's and then run all of the
up migration's, but I can't do it right now.
Here's why it tries.
It's thinking about it.
But I happen to have d'hiver running and it's connected to the database.
And since the database is connected, we get an error.
The database bookings is being accessed by other users.
But if I go over here now and quit out of Dvor, as soon as that little dot disappears that I know it's
quit.
It's giving me the warning message.
Yes, quit.
It's gone now if I clear the screen and run so to reset again, it will drop everything and create everything.
So when I go back here and look at my DB ever again, what it's done is completely recreate our database.
And this will be very useful for us as we're going through.
So we'll actually have in our bookings we have all of our tables.
So under schemas, under public, there's all of our tables.
And if I go and insert a row into one of these tables of diver, go back and run.
So to reset, start up diver and look at it again, you'll see that that row I entered is gone and it's
recreated our database from the ground up.
So what we'll be able to do in the not too distant future is to actually add some migration's that populate
our database with default data so we can be working along and populating our database, adding records,
deleting records.
And at some point you'll say to yourself, wow, it would be great if I could start with a clean copy
of the database with known default data.
And we can do that using SOTA with only one limitation.
And it's a minor one.
And I'll draw to your attention when we get to that point.
But right now, we've created all of our migration's I've added all of mine to get except for the last
two we just created, which I'm going to do right now.
I'll add those together.
And we have a means of maintaining our database structure and our database integrity committed right
to our git repository.
And this will be ever so helpful as we continue through this course.
All right.
Time to move on.
And it's actually time to start working on connecting our code to a database.
Right, Engo.