I'm developing a Rails 3 application (with MySQL as RDMS) to manage availability/occupancy for some Rooms (it's an hotel-like app) In my case, the problem is I've to keep up in the system 2 different requirements because one room can be rented for:
- Some months (for example 6 monts)
- Some days/weeks/weekend
Clearly the app has to show for each room in a given date, if it is available or not, and which user is renting; and on the other side, one user can search one room for a given date range. The date range can be some fixed date or some months range (from September to March for instance) and I know this is something not related with the DataBase deisgn but I've to keep in mind.
To get this system working in a efficient way, I thought to create a table YEAR composite by a reference to the Room and an array (representing 1 year) of 365 elements when each element could be 0 or 1, when 0 means available and 1 means rented.
Adopting this solution I'll have to face with some problems:
- Return very quick results when an user is searching for a room during some months.
- Managing 'cross-years'ranges (for instance, from 20th of December of 2012 to 13rd of January of 2013)
- Leap years
and the last thing, I'm tying to avoid SQL procedure or mid-night processes (if it's possible)
I'm sure there are better ways to design this problem in SQL... Could some of you help me? or giving me some hint?