21 lines
1021 B
Markdown
21 lines
1021 B
Markdown
|
|
# Proposal: Synchronize Heartbeat Data to Room Status Table
|
||
|
|
|
||
|
|
## Background
|
||
|
|
The `room_status.room_status_moment` table is a shared table for real-time device status. The heartbeat service needs to synchronize relevant fields from Kafka messages to this table.
|
||
|
|
|
||
|
|
## Changes
|
||
|
|
1. **Database Schema**:
|
||
|
|
* Add `bright_g` (INT2) and `agreement_ver` (TEXT) columns to `room_status.room_status_moment`.
|
||
|
|
* Add a UNIQUE INDEX on `(hotel_id, room_id, device_id)` to support efficient UPSERT operations.
|
||
|
|
|
||
|
|
2. **Application Logic**:
|
||
|
|
* Implement `upsertRoomStatus` in `DatabaseManager`.
|
||
|
|
* Call this method in `HeartbeatProcessor` after successful insertion into the history table.
|
||
|
|
* Map `version` to `agreement_ver` and `bright_g` to `bright_g`.
|
||
|
|
|
||
|
|
## Tasks
|
||
|
|
- [ ] Update `docs/room_status_moment.sql` with new columns and index.
|
||
|
|
- [ ] Update `docs/plan-room-status-sync.md` with new fields and finalized plan.
|
||
|
|
- [ ] Implement `upsertRoomStatus` in `DatabaseManager`.
|
||
|
|
- [ ] Integrate into `HeartbeatProcessor`.
|