about summary refs log tree commit diff
path: root/src/bin
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabui@proton.me>2026-10-13 23:36:39 +0300
committerAlexander_Kabui <alexanderkabui@proton.me>2026-10-14 07:28:51 +0300
commit22ff53e2d65e47df27d76aa7420a146074c00282 (patch)
tree07f550107ebb9501b1fa79e8e8d6b2d48210572d /src/bin
parenta188b75157516c5e00dd130d9ca8dfbd6cf36679 (diff)
downloadgenenetwork4-22ff53e2d65e47df27d76aa7420a146074c00282.tar.gz
config: GN4_DB_MODE (mariadb optional on dev) + no-DB hardening
* src/config.rs (DbMode, Config.db_mode, parse_db_mode): add
GN4_DB_MODE=dev|production in the layered config; dev runs with no
configured DB; fail-closed parse (a typo refuses).
* src/db.rs (DbError, pool, probe), src/error.rs (ApiError::from_db):
mint a typed 503 db_unavailable at the db::pool() choke point,
distinguishing Unavailable from Query.
* src/main.rs: loud no-DB startup line; production refuses to start
(exit non-zero) before axum::serve.
* src/routes/{accessions,datasets,groups,mapping_methods,publications,species,traits}.rs:
route every DB error through ApiError::from_db.
* src/bin/gn-indexer.rs: refuse to build an index when the DB is unreachable.
* tests/no_db.rs: pin no-DB degradation (search 200 partial, DB routes 503).

His ask (DM 2026-10-12): "Make it an option to switch it off for
development machines? I mean mariadb." The no-DB hardening is ours
(review-driven). Default GN4_DB_MODE left unflipped (=dev); the flip needs
owner sign-off.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/gn-indexer.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/bin/gn-indexer.rs b/src/bin/gn-indexer.rs
index 3b70945..d437699 100644
--- a/src/bin/gn-indexer.rs
+++ b/src/bin/gn-indexer.rs
@@ -67,6 +67,20 @@ fn main() -> ExitCode {
         publish_filter,
     };
 
+    // Fail loudly BEFORE touching the index when the database is
+    // unreachable: the crawl needs it, and a run must never build an
+    // empty index. The message names SQL_URI/GN4_DB_MODE so the cause is
+    // unambiguous. (The crawl itself also fails, but this makes the
+    // reason explicit and keeps the index untouched by construction.)
+    if let Err(error) = genenetwork4::db::probe() {
+        eprintln!(
+            "gn-indexer: database unreachable (SQL_URI; GN4_DB_MODE={:?}); refusing to build an \
+             index: {error}",
+            config.db_mode
+        );
+        return ExitCode::from(1);
+    }
+
     let result = match mode.as_str() {
         "full" => run_full(&run_config),
         "incremental" => run_incremental(&run_config),