‫All right.
‫So with those tables in place,
‫now let's create the booking table
‫and set up the relationships that we talked about earlier.
‫So new table called bookings.
‫And then here, let's start with the start date,
‫and this one should be a timestamp.
‫So this is going to be a date
‫and so here in Postgres, those are called timestamp.
‫So we have a start date and an end date as well.
‫So when the guest leaves, so again, a time stamp.
‫Then we also want the number of nights
‫which in our application will be automatically calculated
‫but it's still a great idea to store that here
‫as an integer.
‫Then the number of guests also an integer.
‫And then let's store the prices.
‫So there will be a cabin price
‫so the price that a guest pays for just a cabin.
‫So let's make this a float.
‫And then there will also be some extras price.
‫So for example, for breakfast and for other stuff
‫that maybe the hotel might want to add later.
‫And then finally, there is a total price
‫which is the sum of the other two.
‫So then of course it also needs to be a float.
‫Then here we have the status
‫which will contain basically the status of the booking.
‫So whether it is currently checked in, if it is checked out
‫or maybe the guest hasn't even arrived yet.
‫So then we will call it unconfirmed.
‫So let's make this text.
‫And this really here is the longest one,
‫so we still need some more.
‫One of them is whether the user has bought breakfast
‫for this booking, so has breakfast,
‫and here we can use the bullion.
‫So just a true or false.
‫Then we also want to store whether the user has already
‫paid this or not, because there might be the possibility
‫of the guest only paying at the hotel.
‫So only once they arrive.
‫And finally, we just want to store some observations
‫about the booking as well.
‫So maybe they want to let the hotel know when they arrive
‫or something like that.
‫Now, okay so these are all the fields that we need for now.
‫So the basic fields
‫but now it is time to actually connect this table
‫with the guests and with the cabins table
‫or in other words, to establish relationships between these.
‫So as we learned two lectures ago
‫the way we are going to do this is by storing the cabin ID
‫and the guest ID right here in a booking.
‫So let's do that.
‫So cabin ID and now comes the most important part.
‫So to connect these two, we click here
‫which actually shows us that this is to edit
‫the foreign key relation.
‫And so here is where we do that.
‫So let's then select a table to reference
‫which is going to be the cabin.
‫And the column in there that we want to connect
‫this with is exactly this ID.
‫So this is exactly what we had in the diagram
‫two lectures ago, and this is all we need to do.
‫So now this table is connected with the ID
‫or with the cabin ID.
‫And now let's do the same thing for a guest.
‫So the guest ID will be a foreign key for the guest's table
‫and in particular the ID column.
‫All right, and so now let's then also create a brand new row
‫in this table to see how the connection between
‫these tables actually looks like in practice.
‫So let's add the start date.
‫And here we can just click on this calendar.
‫So let's say I want to arrive next Monday,
‫and I want to leave then on the Friday.
‫Yeah, so that's going to be just four nights.
‫So we can write that here with two guests.
‫And the price here will be 300, let's say.
‫Then let's say I also want breakfast, so that's going to
‫be 60 at least if the price of breakfast is 15
‫as we were saying, and actually that should be 120
‫because we are two guests, then the total price makes it 420
‫and the status is unconfirmed.
‫So I didn't arrive yet at the booking.
‫So I do have breakfast.
‫I already paid, let's say
‫and I will arrive at 10:00 PM so a bit late.
‫So it's nice to let them know about this.
‫And now here we can then actually select the cabin.
‫So let's click here, which will move to the cabin table.
‫And so here I can now select this one
‫because it's the only one that exists.
‫So I'm going to be in cabin number one.
‫And now I also need to select my own guest information
‫which again is this one with the ID of one.
‫So then that's the reason why the one appears there.
‫And so as I save this, then exactly like we were saying
‫these important IDs are then saved here.
‫And we can also see that this is a foreign key relation.
‫Now, this course is by no means a database or an SKL course
‫but just as a side note, if in the future you want to model
‫these kind of relations on your own,
‫you need to think of these relations in terms of the number
‫of entities that can be involved.
‫So that sounds a bit difficult
‫but let me give you an example.
‫So here with the bookings and the cabins
‫each booking can only have exactly one cabin, right?
‫So one booking can only be about one cabin
‫not two, not three, but really only one.
‫On the other hand, one cabin can be involved in many,
‫many different bookings.
‫So over time a cabin might be booked, for example, 100 times
‫but each booking can really only be for one exact cabin.
‫And so that's what I meant initially when I said
‫that we need to take into account the number of entities
‫basically that are involved.
‫And so this is important
‫because we need to place the foreign key in the table
‫that can only reference exactly one other row
‫from another table.
‫And so that's why the cabin ID
‫and the guest ID are right here.
‫So, because again, each booking can only be about
‫one exact cabin and one exact guest.
‫All right.
‫But anyway, with this, we finished building our tables here
‫and so let's just quickly move on.