RFID Events
The rfid_events table is the core of Parlevel's real-time tracking. Every tag detection by the relay creates a row here.
Table structure
| Column | Type | Description |
|---|---|---|
id | bigint PK | Auto-increment |
tag_epc | text | EPC of the detected tag |
location_id | bigint FK | Location where the scan occurred |
from_location_id | bigint FK | Previous location (for movement events) |
to_location_id | bigint FK | Destination location (zone/storeroom ID) |
event_type | text | "scan", "move", "offline" |
rssi | numeric | Signal strength at time of scan (dBm) |
reader_id | text | ID of the reader that detected the tag |
created_at | timestamptz | Timestamp of the event |
Zone assignment
A product's zone assignment is derived from rfid_events, not from a direct column on products or products_tag. To find which zone a product is currently in:
SELECT DISTINCT ON (pt.tag_epc)
pt.tag_epc,
pt.product_id,
re.to_location_id AS zone_id,
re.created_at
FROM products_tag pt
JOIN rfid_events re ON re.tag_epc = pt.tag_epc
WHERE re.to_location_id IS NOT NULL
ORDER BY pt.tag_epc, re.created_at DESCThe most recent event with a to_location_id gives the current zone for each tag.
Event types
event_type | When created | Description |
|---|---|---|
"scan" | Every ingest POST | Tag was seen by the reader |
"move" | When tag moves between areas | from_location_id → to_location_id transition |
"offline" | When tag stops being seen | Tag has left antenna range |
Offline detection
A tag is considered offline when it stops appearing in ingest events for a configurable period. The ingest pipeline:
- Compares the incoming tag list against recently-seen tags
- Tags missing from the current scan that were present in the previous N scans trigger an
"offline"event - The
products_tag.tag_statusis set to"Offline"
Live tag presence
For real-time presence (is a tag currently in range?), the useLiveTagPresence hook polls the relay directly rather than querying Supabase. This gives sub-second presence updates without waiting for database writes.
Supabase events are used for persistent history and zone assignment — not for live "is it here right now?" checks.
Realtime subscriptions
The Parlevel UI subscribes to rfid_events inserts via Supabase Realtime to update the area management page without a page reload. New events trigger a refetch of storeroom/zone data.
The useRealtimeStorerooms hook manages this subscription. Note: only isLoading (initial fetch) blocks rendering — background refetches triggered by realtime events update the UI silently.