An empty rooms table is not a neutral state
A three room, five bed spa was being scheduled as though it had one bed, and nothing was throwing an error. The rooms table was just empty.
The shape
The app is the multi-tenant management tool I am building for Autosterea's local business clients: plain Node http, pg, server rendered HTML, no build step, one VPS, one Postgres database. Until this week the bookings for the first tenant, a Seattle head spa, lived in GoHighLevel's calendar. GoHighLevel is a good messaging tool. It knows nothing about rooms, beds, or a spa's last booking cutoff, and it was offering 21:00 starts against a 20:30 one.
So the calendar moved into the database that already owns everything else. Four internal endpoints, slots, hold, confirm and release, which means the booking backend needs no database credential of its own. 47 concurrency tests before the cutover and 19 acceptance checks after it. GoHighLevel is now a messaging channel and nothing else.
old: GoHighLevel owns the calendar, knows nothing about rooms or beds, offers 21:00 starts against a 20:30 cutoff
new: our Postgres owns availability, rooms and bed capacity, 48 candidate slots, 43 bookable, last one 20:30An empty table is a value
Migration 014 created the rooms table. Nothing ever put a row in it.
That is not a neutral state. lib/slots.js has a documented fallback for a tenant who has not configured rooms yet: a single synthetic room of capacity 1, open to every service. Perfectly reasonable as a default for a brand new tenant. Applied to a spa with three rooms and five beds, it meant the whole business was being scheduled as one bed.
The failure direction was at least the safe one. A phantom capacity of 1 under books, so nobody was ever going to arrive and find their bed taken. It would simply have refused most of a normal day, and a refused booking looks exactly like no demand. That is the part worth sitting with: the bug had no error, no alert, and its only symptom was an emptier calendar than the business deserved.
Migration 017 seeds the real layout. One head spa room with a couple bed, capacity 2. One solo head spa room, capacity 1, convertible to massage when the day needs it. One massage room, capacity 2. Five guest slots across three rooms, and occupancy has to count beds, not rooms. They are seed values rather than hardcoded truth, because the settings screen already edits rooms, so when the spa rearranges a room the owner changes it there and the calendar follows.
The hold that could still confirm
The blocker I had parked the engine on was worse than the rooms table.
confirmBooking matched status = 'hold' and never looked at hold_expires_at. An expired hold whose slot may already belong to somebody else could still confirm, which is a straight double booking. The expiry check now sits in the WHERE clause so it evaluates atomically with the update, and an expired hold returns a distinct hold_expired code rather than a generic not found, because on a paid booking that specific failure means we have taken money for a time we cannot honour. It needs a refund and a human, not a retry.
The money path is where I made the failure directions deliberately asymmetric. A declined card releases the hold, because the guest has paid nothing and somebody else should get the slot. A charge that succeeds and then fails to confirm does not release it. Releasing there would leave a guest without the money and without the time, so it stays held and shouts.
Then a smaller one with a straight line to the front desk. confirmBooking set payment_status = 'paid' unconditionally, so a guest who chose to pay at the spa was recorded as already settled and the front desk had no reason to collect. It now follows the payment reference: a Square id means paid, no reference means cash is still owed.
Blocking time without inventing a booking
The spa's existing bookings still live in the tool it is moving off, and our engine cannot see them. On the day I cut over, the spa was fully booked there and our calendar showed the day as completely free. Without somewhere to put that, the engine would have cheerfully sold beds that were already taken.
Migration 020 adds calendar blocks, and the important decision is where they are enforced. Not in the view that renders the slot picker. In usedCapacity(), the one chokepoint the hold path goes through, so a direct POST to the booking API cannot book over a block either. Hiding a slot from the picker is presentation. The chokepoint is the guarantee.
A block with no room covers the whole spa, and in the slot computation it expands to one pseudo booking per room consuming that room's full capacity, so the slots module needs no concept of blocks at all. It is also just the general tool for a day off or a room out of service. Before it, the only way to make a slot unavailable was to insert an appointment, which pollutes revenue and guest counts with things that were never bookings.
Two of these caught each other. The block patch referenced a blocks variable that an earlier script had died before writing, so every slot lookup would have thrown, and the deploy smoke test did not catch it because the slots endpoint is not an app screen. My first block test then used wrong date arithmetic and quietly booked tomorrow instead of the blocked day, testing nothing. Redone against the real Seattle date: a blocked day returns 409, an open day returns 200.
What I learned
An empty table is a value, not an absence. A rooms table with no rows did not mean "capacity unknown," it meant "one bed," because a fallback written for new tenants was doing exactly what it was designed to do. Defaults are the loudest code you never read, and the ones that quietly under serve are harder to notice than the ones that break, because the symptom is an empty calendar rather than an exception.
Enforce at the chokepoint, not at the view. Blocks live in usedCapacity() rather than in the slot picker, so a hand rolled POST to the booking API hits the same wall a guest does. Anything enforced only in the thing that draws the screen is a suggestion.
A cutover breaks whatever was listening to the old path. Notifications were queued inside the endpoint the old flow called, and the native flow does not call it, so the cutover would have silently stopped every confirmation and every reminder while every booking still succeeded. Queueing moved to the confirm endpoint, the point at which a booking actually becomes real. When you move a path, go and look at what was subscribed to the old one.
If your booking software is renting you a calendar that does not understand your business, that is the kind of thing Autosterea replaces.
First published on ravikantdewangan.com.

