Parameters
| Name | Type | Mode |
|---|---|---|
| i_guest_id | integer | IN (DEFAULT NULL) |
| p_rebuild | boolean | IN (DEFAULT true) |
| i_force | boolean | IN (DEFAULT false) |
| phase | text | OUT |
| visits | bigint | OUT |
| guests | bigint | OUT |
| room_nights | bigint | OUT |
| revenue | numeric | OUT |
Rebuild public.guest_history from registration UNION backup.registration (status O only) and recompute the guest roll-up. i_guest_id NULL = every guest. p_rebuild false = report only. Idempotent: re-running produces the same rows. Fills in MISSING stay rows only — existing rows are left untouched (write-once), so a rebuild can never replace real figures with values recomputed from sources that have already been purged. i_force = true overwrites existing rows and is the deliberate repair path. Note it can only recover stays that still exist in public.* or backup.* — stays already purged past ARCHIVE_PURGE_DAYS are gone for good.
| Name | Type | Mode |
|---|---|---|
| i_guest_id | integer | IN (DEFAULT NULL) |
| p_rebuild | boolean | IN (DEFAULT true) |
| i_force | boolean | IN (DEFAULT false) |
| phase | text | OUT |
| visits | bigint | OUT |
| guests | bigint | OUT |
| room_nights | bigint | OUT |
| revenue | numeric | OUT |