‫So in order to figure out
‫which tables we should
‫actually create inside supabase,
‫so in our database,
‫we first need to think about our application state.
‫Now in a big application like this,
‫modeling state becomes a bit different
‫because we think more about state categories
‫or state slices on a much higher level.
‫So we're not gonna plan state
‫at a component level
‫but really on the page
‫and on the application feature level.
‫So let's bring back our feature categories here
‫and then from here we can basically figure out
‫what state we are going to need
‫in order to power all these features.
‫So in order to actually be able
‫to build out those features.
‫So for the bookings feature,
‫we are probably going to need some bookings state
‫and the same for the cabins,
‫and also the same for the guests.
‫So all of these are really different features
‫and so each of them will need to have their own state
‫in order to manage all this data.
‫Next up, we have the dashboard
‫and the check in and check out features,
‫which can both be powered
‫also by the bookings state.
‫So the dashboard will simply display
‫a few statistics about recent bookings
‫and the check in feature is basically
‫all about updating the booking
‫of a certain user from checked out to checked in
‫or also the other way around for check out.
‫So again, these two, all they're going to need
‫is just the booking state
‫or the bookings data.
‫Next up we have the application settings
‫which will require its own state slice.
‫And finally, for authentication,
‫we are going to need some users.
‫And so these will again be stored
‫inside their own remote state.
‫So as I was just saying,
‫all of this state,
‫so these five states
‫or state slices are going to
‫be global remote state,
‫and they will be stored within supabase
‫and managed on the front end using React Query.
‫And so basically for each of these state slices,
‫there will be one table in our supabase database.
‫So from now on, let's actually
‫no longer call this state slices,
‫but really call them data tables,
‫which is more in line with database design.
‫Now okay, so with this,
‫we now know exactly which tables
‫we need to create,
‫but there is one very special table here
‫which is the bookings table.
‫And so let's take a closer look
‫at how we are going to model that data.
‫So if we think about this,
‫a booking is essentially
‫a guest renting a cabin, right?
‫So a booking needs information
‫about what guest is booking which cabin,
‫or in other words,
‫creating a new booking
‫is all about connecting
‫a cabin with a guest.
‫And therefore, we somehow will need
‫to connect all of these tables.
‫Now in technical terms behind the scenes,
‫supabase uses a Postgres database
‫which is a relational database powered by SQL.
‫Therefore, in order to join these tables,
‫we use something called foreign keys.
‫Now, you don't need to know anything
‫about SQL or about these terms.
‫I'm just quickly explaining
‫how we can model this data
‫and how we should connect these tables.
‫But the technical terms really don't matter.
‫So as we were just saying earlier,
‫each booking basically needs to know which guest
‫is actually doing the booking.
‫And so therefore, what we're going to do
‫is to take the guest's ID
‫and store that inside a new field
‫inside the booking called guest ID.
‫And the same thing with the cabin.
‫So the booking needs to know
‫which cabin was actually booked.
‫And so again, we will store the cabin's ID
‫inside a special field of the booking called cabin ID.
‫And so these two,
‫so guest ID and cabin ID
‫are the foreign keys inside the booking.
‫Now okay, and so let's just quickly recap this.
‫So essentially, we connect a booking with a cabin
‫simply by storing the cabin's ID,
‫which is the primary key of the cabin,
‫inside the bookings cabin ID,
‫which is then the foreign key.
‫And we also do the exact same thing with the guest.
‫So hopefully that made sense
‫but if it's still a bit confusing,
‫then that's no problem at all.
‫It will make more sense
‫once we actually implement this inside supabase.
‫So next up, let's create all the more simple tables
‫and then after that
‫we will create the booking table,
‫and then do these connections
‫that we just talked about.