feat: add Phase 25.5a server-side device config API endpoints

- Add database migration (migrate_phase25_5a.sql):
  * Add owner_name, car_model, device_name, avatar_path columns to devices table
  * Add config_version and config_updated_at for cache invalidation

- Add server/modules/device_config.py:
  * get_device_config(device_id): retrieve config for Pi sync
  * update_device_config(device_id, data): update config with validation

- Add server API endpoints:
  * GET /api/device-config (authenticated with device_key, Pi fetches config)
  * POST /api/device-config (authenticated as user, admin updates config)

- Enhance server/modules/db.py:
  * Add get_device_by_id() function to retrieve all device config fields

Phase 25.5a enables server-side device identity management and connection-driven sync.
Pi will fetch from this endpoint when internet available, keeping config in sync.

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Mathieu Moran
2026-08-10 16:46:52 -04:00
co-authored by Copilot
parent ed78700005
commit 2395cf6dc4
4 changed files with 164 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
-- Phase 25.5a: Device configuration sync
-- Adds columns to store device identity (name, car, avatar, etc) on server
-- Pi fetches and caches these values when internet available (connection-driven sync)
ALTER TABLE devices ADD COLUMN IF NOT EXISTS owner_name TEXT DEFAULT '';
ALTER TABLE devices ADD COLUMN IF NOT EXISTS car_model TEXT DEFAULT '';
ALTER TABLE devices ADD COLUMN IF NOT EXISTS device_name TEXT DEFAULT '';
ALTER TABLE devices ADD COLUMN IF NOT EXISTS avatar_path TEXT DEFAULT 'img/yaris.png';
ALTER TABLE devices ADD COLUMN IF NOT EXISTS config_version INTEGER DEFAULT 0;
ALTER TABLE devices ADD COLUMN IF NOT EXISTS config_updated_at TIMESTAMPTZ DEFAULT now();
-- Index for faster lookups
CREATE INDEX IF NOT EXISTS idx_devices_name ON devices(name);