ffced44bfb
Build and Push processor / build (push) Successful in 58s
positions.device_id stores the IMEI (text); entry_devices.device_id is a
uuid FK to devices.id. snapshot.ts and device-event-map.ts joined the two
columns directly, causing:
- snapshot.ts: Postgres rejected with `operator does not exist: uuid =
text` (42883). The registry caught the error and returned an empty
snapshot, masking the failure.
- device-event-map.ts: cache keyed on entry_devices.device_id (uuid),
but broadcast.ts:141 looks up by position.device_id (imei). Cache
missed every record → no live frames fanned out, silently.
Both queries now hop through the devices table (devices.imei =
positions.device_id, devices.id = entry_devices.device_id). The
device-event-map cache aliases d.imei AS device_id so cache keys stay
IMEI strings — broadcast.ts is unchanged.
The integration-test fixture schema previously had entry_devices.device_id
as text (IMEI) — a deliberate simplification that hid the production type
mismatch. Now matches production: adds a devices table and changes the FK
to uuid. seedDatabase inserts devices first.
178/178 unit tests pass. Integration test exercises the corrected join
shape.
46 lines
2.1 KiB
SQL
46 lines
2.1 KiB
SQL
-- test/fixtures/test-schema.sql
|
|
--
|
|
-- Minimum subset of the production schema required by live.integration.test.ts.
|
|
-- Intentionally a simplified subset of the Directus-managed schema — keeps only
|
|
-- the columns the Processor's live-broadcast queries actually read.
|
|
--
|
|
-- Maintenance note: keep in sync with the real schema when join shapes change.
|
|
-- The integration test runs the real queries from device-event-map.ts and
|
|
-- snapshot.ts unmodified, so the column types here must match production.
|
|
|
|
-- events — the container for entries.
|
|
-- Processor reads events.id (snapshot WHERE e.event_id = $1).
|
|
CREATE TABLE IF NOT EXISTS events (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid()
|
|
-- Real schema also has: organization_id FK, name, slug, discipline, starts_at, ends_at.
|
|
);
|
|
|
|
-- entries — race entries belonging to an event.
|
|
-- Processor reads entries.id and entries.event_id.
|
|
CREATE TABLE IF NOT EXISTS entries (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
event_id uuid NOT NULL REFERENCES events (id) ON DELETE CASCADE
|
|
-- Real schema also has: vehicle_id, class_id, race_number, status, etc.
|
|
);
|
|
|
|
-- devices — durable hardware catalog.
|
|
-- Processor reads devices.id and devices.imei (joined to positions.device_id).
|
|
-- positions.device_id stores the IMEI text; entry_devices.device_id stores the
|
|
-- devices.id uuid. This table is the bridge that lets snapshot.ts and
|
|
-- device-event-map.ts translate between the two without `uuid = text` errors.
|
|
CREATE TABLE IF NOT EXISTS devices (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
imei text NOT NULL UNIQUE
|
|
-- Real schema also has: model, serial_number, notes, date_created, date_updated.
|
|
);
|
|
|
|
-- entry_devices — maps a device (uuid FK) to an entry.
|
|
-- Real schema (and this fixture): device_id is uuid FK to devices.id.
|
|
-- Live-broadcast joins translate to/from positions.device_id (IMEI text)
|
|
-- via the devices table.
|
|
CREATE TABLE IF NOT EXISTS entry_devices (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
entry_id uuid NOT NULL REFERENCES entries (id) ON DELETE CASCADE,
|
|
device_id uuid NOT NULL REFERENCES devices (id) ON DELETE CASCADE
|
|
);
|