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"))]
7
extern crate self as server;
8

            
9
pub mod auth_keys;
10
pub mod bootstrap;
11
pub mod config;
12

            
13
pub mod db;
14

            
15
//pub mod transaction;
16
pub mod account;
17
pub mod artifact_mgmt;
18
pub mod command;
19
pub mod commodity;
20
pub mod error;
21
pub mod logical;
22
pub mod provision;
23
pub mod script;
24
pub mod split;
25
pub mod tag;
26
pub mod user;
27
use exitfailure::ExitFailure;
28
use sqlx::any::install_default_drivers;
29
use tokio::{runtime::Handle, task::JoinHandle};
30

            
31
#[macro_use]
32
extern crate rust_i18n;
33

            
34
i18n!("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).
41
pub 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

            
51
pub async fn start() -> JoinHandle<Result<(), ExitFailure>> {
52
    let handle = Handle::current();
53

            
54
    handle.spawn(boot())
55
}