1

I'm wanting to find a way to how I can implement a booking system that lets users put a start date on the booking and generate the end date whenever.

Lets take a house renting example. Say I wanted to book a house from a particular starting date, but I'm not sure when I'll leave, the maximum stay for users who don't put a end date is 3 days, how could I do build my database so there aren't any booking overlaps?

The current structure I have is:

booking

booking_id      | integer | not null default nextval('booking_booking_id_seq'::regclass)
houseId | integer |
user_id         | integer | not null

booking_date

 booking_date_id | integer                     | not null default nextval('booking_date_booking_date_id_seq'::regclass)
 book_from       | timestamp without time zone | not null
 book_to         | timestamp without time zone | not null
 booking_id      | integer                     |

I'm wondering whether I store an extra field in the booking entity is_stayAndLeaveWhenever

and then in the booking_date I'd just store the book_to with the book_from + 3 days (max stay without choosing leave date)

Is that a solid solution?

  • Why 2 entities? Is booking supposed to have multiple booking_date? – Serg Jun 23 '16 at 8:02
  • Good point...But building it this way means if I ever want todo something fancy with the booking -> booking_dates, I can. @Serg – James111 Jun 23 '16 at 8:04
  • OK then why not 3 entities, separating book_from and book_to ? – Serg Jun 23 '16 at 8:07
  • Seems pointless doing that @Serg – James111 Jun 23 '16 at 23:20
2

the maximum stay for users who don't put a end date is 3 days,

Default end date in db = 3 days. Maybe marker "tentative". Issue being - if you do not know when they move out and can not have overlap, you MUST reserve the maximum stay.

So, your solution is as good as it gets.

| improve this answer | |
  • Yeah I think you're right. Was just thinking there may be a smarter way of doing this! – James111 Jun 23 '16 at 8:07
  • Any idea how I'd implement a billing service for each of the bookings? If you could point me towards a tutorial or example that'd be great! – James111 Jun 23 '16 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.