Phase 5 of Migration

This commit is contained in:
2026-04-17 15:51:27 +03:00
parent da4608c937
commit a605143c5d
5 changed files with 449 additions and 25 deletions

View File

@@ -402,12 +402,17 @@ await log_action(db, actor_id, actor_name, "UPDATE", "customer", id, label, chan
---
## Phase 5 — MQTT Live Data Cutover
**Status: NOT STARTED**
**Prerequisite:** Phase 1 complete (device_logs in Postgres)
**Status: COMPLETE** — Postgres live ingestion + partition manager active 2026-04-17
This phase switches the **live MQTT ingestion** from SQLite to Postgres.
### What changed
- New `backend/database/pg_mqtt.py` — all MQTT functions rewritten for Postgres (raw SQL, no ORM)
- `database/__init__.py` — re-exports from `pg_mqtt` instead of `core`
- `main.py` — removed `db.init_db()` / `db.close_db()`, added `db.partition_manager_loop()`
- `mqtt/router.py` WebSocket auth — reads from Postgres `staff` table instead of Firestore `admin_users`
- `device_logs` partitioned writes, `heartbeats`/`commands` as plain tables
- `purge_loop` still runs for heartbeats/commands; device_logs purged via partition drops
### Steps
### Steps (original plan, now implemented)
1. Update `database/core.py` `insert_log`, `insert_heartbeat`, `insert_command` to write to Postgres
2. Update read functions (`get_logs`, `get_heartbeats`, etc.) similarly
3. The partition management background job: each month, at startup or via a cron, ensure next month's partition exists:
@@ -470,7 +475,7 @@ backend/
| 2 | Firestore → Postgres (data migration) | **COMPLETE** — all 5 scripts ran successfully on VPS 2026-04-17 |
| 3 | Staff auth cutover | **COMPLETE** — Postgres auth live 2026-04-17 |
| 4 | Audit log system | **COMPLETE** — shared/audit.py live, wired into auth + staff 2026-04-17 |
| 5 | MQTT live data cutover | NOT STARTED |
| 5 | MQTT live data cutover | **COMPLETE** — Postgres live ingestion + partition manager 2026-04-17 |
Update this table as each phase completes.