fix(accommodations): a booking that moves carries its stop instead of rebuilding it

Correcting a booking's date deleted the day stop it had mirrored and inserted
a fresh one. A day stop is not just a day and a place: its participants and any
road-trip day boundary hang off its id by ON DELETE CASCADE, and its note, its
hour and its end-of-day flag live in its own columns. All of it went, silently,
for an edit that only meant to move the night one day on. The row is carried
across now, seated by its check-in the same way an insert would be, and the
delete-and-insert is kept only for the case where the target day already holds
that place under a stop of the traveller's own.

Three more holes in the same mirror, found alongside it:

Dropping a night while keeping the place cleared accommodation_id server side
and told nobody. Days hides a stop that carries a booking id, so on every other
screen the place stayed invisible on a day it was standing on.

A night is seated by its check-in, which renumbers the stops around it, and
nothing said so. The day that changed now sends its order along.

Deleting a place cancelled the nights booked there, which takes each night's
partner booking and that booking's expense with it, and announced neither. The
Bookings list kept the reservation and the Costs total kept the money until a
reload, and an expense linked by reservation_id is not one the place-linked
sweep finds.

Also: day_assignments.accommodation_id went in as a bare INTEGER, so shortening
a trip past a booking's last night cascaded the booking away and left the stop
pointing at nothing, hidden from Days for good while the route still drove to
it. Migration 234 clears the ones already out there and adds a trigger, which
SQLite fires even when the booking went down with a cascade. And a duplicated
trip now carries the stop's booking id, the booking's check-in window and a
place's fill_percent, none of which the copy took along.
This commit is contained in:
Maurice
2026-09-13 22:22:23 +02:00
parent 0cc6dcf8aa
commit 54e5525568
13 changed files with 412 additions and 59 deletions
+32
View File
@@ -4868,6 +4868,38 @@ function runMigrations(db: Database.Database): void {
}
}
},
/*
* Let go of a booking the day stop can no longer reach.
*
* day_assignments.accommodation_id was added as a bare INTEGER, and the only
* code that ever clears it looks the stay up by id. A stay can also vanish
* without anybody asking: day_accommodations.end_day_id is ON DELETE CASCADE,
* so shortening a trip past a booking's last night deletes the booking while
* the stop on its first night survives, now pointing at nothing. Days hides any
* stop that carries an accommodation_id, so the hotel drops out of the day list
* on every surface while the route still drives to it, and the id is
* AUTOINCREMENT, so nothing will ever come along and free the row.
*
* A trigger rather than a column rebuild: day_assignments is referenced by two
* cascading tables of its own, and SQLite fires this even when the stay went
* down with a foreign-key cascade.
*/
() => {
db.exec(`
UPDATE day_assignments SET accommodation_id = NULL
WHERE accommodation_id IS NOT NULL
AND accommodation_id NOT IN (SELECT id FROM day_accommodations)
`);
db.exec('CREATE INDEX IF NOT EXISTS idx_day_assignments_accommodation_id ON day_assignments(accommodation_id)');
db.exec(`
CREATE TRIGGER IF NOT EXISTS trg_release_stop_on_stay_delete
AFTER DELETE ON day_accommodations
BEGIN
UPDATE day_assignments SET accommodation_id = NULL WHERE accommodation_id = OLD.id;
END
`);
},
];
if (currentVersion < migrations.length) {