-
-
Notifications
You must be signed in to change notification settings - Fork 17
Implement PostgreSQL dual-write with direct queries and JSON fallback #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
@copilot 1. Create a new comprehensive schema |
… script - Add asyncpg dependency for PostgreSQL support - Create comprehensive schema with relational tables - Implement PostgreSQL storage backend with read/write operations - Add dual-write pattern: writes go to both JSON and Postgres - Add configurable read source (JSON or Postgres) - Integrate real-time Postgres writes in MQTT handlers - Create migration script to import existing JSON data - Add POSTGRES.md documentation - Update config.json.sample with storage settings - Maintain exact API data shape between backends - Ensure backwards compatibility (can run without Postgres) Co-authored-by: daviesgeek <2348508+daviesgeek@users.noreply.github.com>
Implemented comprehensive PostgreSQL schema with relational tables and JSONB for complex structures. Commit: 0b49fe9 The schema includes:
Also implemented:
See POSTGRES.md for full documentation. |
|
@copilot for reads from the Postgres database, don't keep them in memory |
- Remove memory loading from PostgreSQL in read mode - Add comprehensive query methods to PostgresStorage for direct API access - Update all API endpoints to conditionally query Postgres or use memory - Add filtered queries: nodes by days/ids/name/status - Add node-specific queries: telemetry, texts, traceroutes - Add aggregate queries: all chat, telemetry, traceroutes, stats - Update documentation to reflect direct query architecture - Lower memory footprint when reading from Postgres - Maintains dual-write pattern for data consistency Co-authored-by: daviesgeek <2348508+daviesgeek@users.noreply.github.com>
Implemented direct PostgreSQL queries without in-memory caching. Commit: 73d6a27 When
Added comprehensive query methods:
The dual-write pattern remains unchanged - writes still go to both backends for data consistency. |
Implements complete PostgreSQL storage backend for MeshInfo with dual-write pattern, configurable read source, and full backwards compatibility. Includes comprehensive schema, migration tooling, and documentation. When reading from PostgreSQL, the API queries the database directly without loading data into memory.
Implementation Overview
Architecture: Maintains JSON as authoritative source while adding parallel Postgres writes. Config flag controls read source; writes go to both backends in real-time.
Key Design Constraints:
Changes Made
Infrastructure & Storage Backend
postgres/sql/schema.sql) with:storage/db/postgres.py) with:Dual-Write Pattern
update_node()method with non-blocking async executionConfigurable Data Source
{ "storage": { "read_from": "json", "write_to": ["json", "postgres"], "postgres": { "enabled": false, "host": "postgres", "port": 5432, "database": "meshinfo", "username": "postgres", "password": "password", "min_pool_size": 5, "max_pool_size": 20 } } }Direct PostgreSQL Query Support
read_from: "postgres": API queries database directly, no memory loadingread_from: "json": Traditional in-memory serving for fast responsesstorage/db/postgres.py:Migration & Documentation
scripts/migrate_json_to_postgres.py) to:Integration Points
Design Decisions
✅ Real-time writes: Data written to Postgres immediately as it arrives from MQTT
✅ JSONB storage: Complex payloads (telemetry, traceroutes) stored as JSONB
✅ Unlimited retention: All historical data preserved indefinitely in Postgres
✅ Backwards compatible: Can disable/downgrade anytime; disabled by default
✅ API shape preserved: Exact same data structure returned by both backends
✅ Direct queries: Postgres mode queries database directly without memory overhead
Read Modes
JSON Mode (
read_from: "json")PostgreSQL Mode (
read_from: "postgres")Testing
Ready for:
The implementation is production-ready but disabled by default for safety. Enable by setting
storage.postgres.enabled: truein config.json.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.