/free-stay-challenge

Free Stay database challenge

MIT LicenseMIT

Free Stay Challenge

This is a challenge to be solved with a database only, and consists of the following problem:

"Imagine there is a hotel chain, and they want to reward frequent customers. The following rules apply to the reward program:

  • For every 5 nights of stay within a year, the customer gets another night for free;
  • The program only credits nights based on the stays for the past 12 months;
  • The credited stays can be accumulated to be used at once, or individually;
  • The customer is not awarded free stays if he didn't book 5 or more nights within the past 12 months, even if he had booked more in the past."

In order to solve this I'm using PostgreSQL database and dbmate.

The queries used for solving are in the db/queries folder. To run the queries, the database has to be created, migrations executed and seeds populated.