From 57182c54128320cfb690ee41e8025550cf83c1a1 Mon Sep 17 00:00:00 2001 From: ppfeiffer Date: Fri, 20 Feb 2026 21:59:40 +0100 Subject: [PATCH] fix(db): Datenbank nach data/ verschoben, WAL-Checkpoint + robuster Shutdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - database.path in config.yaml: meshdd.db → data/meshdd.db - data/.gitkeep: Verzeichnis in Git verankert, *.db-wal/shm gitignored - database.py: PRAGMA wal_checkpoint(FULL) vor db.close() für sauberes Schließen - main.py: Shutdown-Schritte einzeln mit try/except gekapselt; db.close() wird jetzt auch bei Fehlern in vorherigen Schritten ausgeführt Co-Authored-By: Claude Sonnet 4.6 --- .gitignore | 2 ++ CHANGELOG.md | 10 ++++++++++ config/config.example.yaml | 2 +- config/config.yaml | 4 ++-- data/.gitkeep | 0 main.py | 20 ++++++++++++++++---- meshbot/database.py | 7 +++++++ 7 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 data/.gitkeep diff --git a/.gitignore b/.gitignore index a54422e..0bdd4cd 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ config/.env *.db *.sqlite *.sqlite3 +data/*.db-wal +data/*.db-shm .idea/ .vscode/ *.swp diff --git a/CHANGELOG.md b/CHANGELOG.md index b8006e0..318a15c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [0.08.18] - 2026-02-20 + +### Changed +- **Datenbankdatei nach `data/` verschoben**: `database.path` in `config.yaml` ist jetzt + `data/meshdd.db`; WAL/SHM-Dateien in `data/` sind gitignored. +- **Sauberes DB-Close**: `database.py` führt vor dem Schließen `PRAGMA wal_checkpoint(FULL)` + durch, damit keine Daten im WAL-Journal verbleiben. +- **Robusterer Shutdown** in `main.py`: Jeder Shutdown-Schritt (NINA, Bot, WebSocket, Web) + ist einzeln mit try/except gekapselt – `db.close()` wird jetzt immer ausgeführt. + ## [0.08.17] - 2026-02-20 ### Changed diff --git a/config/config.example.yaml b/config/config.example.yaml index 685635a..2bf272c 100644 --- a/config/config.example.yaml +++ b/config/config.example.yaml @@ -14,7 +14,7 @@ web: online_threshold: 900 database: - path: "meshdd.db" + path: "data/meshdd.db" auth: session_max_age: 86400 diff --git a/config/config.yaml b/config/config.yaml index fc2a1ba..abf6e88 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,4 +1,4 @@ -version: "0.08.17" +version: "0.08.18" bot: name: "MeshDD-Bot" @@ -14,7 +14,7 @@ web: online_threshold: 900 database: - path: "meshdd.db" + path: "data/meshdd.db" auth: session_max_age: 86400 diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py index 8779c0d..1b06330 100644 --- a/main.py +++ b/main.py @@ -71,10 +71,22 @@ async def main(): await stop_event.wait() finally: logger.info("Shutting down...") - await nina.stop() - bot.disconnect() - await ws_manager.close_all() - await runner.cleanup() + try: + await nina.stop() + except Exception: + logger.exception("Error stopping NINA") + try: + bot.disconnect() + except Exception: + logger.exception("Error disconnecting bot") + try: + await ws_manager.close_all() + except Exception: + logger.exception("Error closing WebSocket connections") + try: + await runner.cleanup() + except Exception: + logger.exception("Error cleaning up web runner") await db.close() logger.info("Shutdown complete") diff --git a/meshbot/database.py b/meshbot/database.py index dbb80f2..0d57f1e 100644 --- a/meshbot/database.py +++ b/meshbot/database.py @@ -22,7 +22,14 @@ class Database: async def close(self): if self.db: + try: + await self.db.execute("PRAGMA wal_checkpoint(FULL)") + await self.db.commit() + except Exception: + logger.exception("Error during WAL checkpoint on close") await self.db.close() + self.db = None + logger.info("Database closed") async def _create_tables(self): await self.db.executescript("""