Skip to main content

server/
lib.rs

1#![recursion_limit = "256"]
2
3// Allows test code within this crate to reference `server::db::MIGRATOR`
4// with the same absolute path that external test crates use — required so
5// the `local_db_sqlx_test` proc macro can emit a single fixed migrator path.
6#[cfg(any(test, feature = "test-utils"))]
7extern crate self as server;
8
9pub mod auth_keys;
10pub mod bootstrap;
11pub mod config;
12
13pub mod db;
14
15//pub mod transaction;
16pub mod account;
17pub mod artifact_mgmt;
18pub mod command;
19pub mod commodity;
20pub mod error;
21pub mod logical;
22pub mod provision;
23pub mod script;
24pub mod split;
25pub mod tag;
26pub mod user;
27use exitfailure::ExitFailure;
28use sqlx::any::install_default_drivers;
29use tokio::{runtime::Handle, task::JoinHandle};
30
31#[macro_use]
32extern crate rust_i18n;
33
34i18n!("locales", fallback = "en");
35
36/// Runs the one-time-per-DB boot sequence: install sqlx drivers, migrate the
37/// admin DB, run the idempotent global seed (`seed_complete`-guarded), and load
38/// config. Every startup path MUST call this before reading config — the web
39/// binary calls it directly; the CLI/server path goes through [`start`]. Safe
40/// to call on an already-booted DB (migrate + seed are idempotent).
41pub async fn boot() -> Result<(), ExitFailure> {
42    install_default_drivers();
43    db::migrate_db().await?;
44    bootstrap::seed().await?;
45    config::load_config().await?;
46
47    log::info!("{}", &t!("The server boot complete"));
48    Ok(())
49}
50
51pub async fn start() -> JoinHandle<Result<(), ExitFailure>> {
52    let handle = Handle::current();
53
54    handle.spawn(boot())
55}