refactor(db)!: adopt project-routed pooled databases

Reorganize WNDB by responsibility and remove legacy scheme endpoints.\n\nRoute analysis and time-series access through project pools, preserve transactional realtime replacement, and refresh GIS materialized views after writes.\n\nAdd database architecture documentation, live pooling coverage, API contract updates, and executable container verification.\n\nBREAKING CHANGE: legacy scheme APIs and flat app.native.wndb module imports are removed.
This commit is contained in:
2026-08-25 18:35:05 +08:00
parent fdbcc5c033
commit fa188af0b1
181 changed files with 8446 additions and 33546 deletions
+36
View File
@@ -1,4 +1,5 @@
import asyncio
from contextlib import contextmanager
from datetime import datetime, timezone
from app.infra.db.timescaledb.repositories.realtime import RealtimeRepository
@@ -65,3 +66,38 @@ def test_get_nodes_by_time_range_normalizes_inputs_to_utc():
datetime(2026, 6, 1, 0, 0, tzinfo=timezone.utc),
datetime(2026, 6, 1, 1, 0, tzinfo=timezone.utc),
)
class _SyncTransactionConnection:
def __init__(self):
self.transactions = 0
@contextmanager
def transaction(self):
self.transactions += 1
yield
def test_realtime_node_and_link_replacement_share_outer_transaction(monkeypatch):
conn = _SyncTransactionConnection()
calls: list[str] = []
monkeypatch.setattr(
RealtimeRepository,
"insert_nodes_batch_sync",
lambda _conn, _data: calls.append("nodes"),
)
monkeypatch.setattr(
RealtimeRepository,
"insert_links_batch_sync",
lambda _conn, _data: calls.append("links"),
)
RealtimeRepository.store_realtime_simulation_result_sync(
conn,
[{"node": "N1", "result": [{"pressure": 1.0}]}],
[{"link": "L1", "result": [{"flow": 2.0}]}],
"2026-06-01T00:00:00Z",
)
assert conn.transactions == 1
assert calls == ["nodes", "links"]