Author:
Hash:
Timestamp:
+16 -6 +/-1 browse
Kevin Schoon [me@kevinschoon.com]
53f6ff21ef8597700bde46c3dc8bc24c1e02f3a4
Sat, 20 Apr 2024 17:26:16 +0000 (1.2 years ago)
1 | diff --git a/ayllu/src/main.rs b/ayllu/src/main.rs |
2 | index ce4afb6..fceb0c5 100644 |
3 | --- a/ayllu/src/main.rs |
4 | +++ b/ayllu/src/main.rs |
5 | @@ -7,7 +7,7 @@ use clap::{Args, Parser, Subcommand}; |
6 | use tokio::runtime::Builder; |
7 | |
8 | use ayllu_config::Reader; |
9 | - use ayllu_database::migrate; |
10 | + use ayllu_database::{migrate, Error as DBError}; |
11 | |
12 | mod job_server; |
13 | mod web2; |
14 | @@ -65,7 +65,11 @@ enum Command { |
15 | migrations: Option<String>, |
16 | }, |
17 | /// Launch the main web server. |
18 | - Serve, |
19 | + Serve { |
20 | + #[clap(short, long)] |
21 | + /// optional path to migrations directory |
22 | + migrations: Option<String>, |
23 | + }, |
24 | /// Offline indexing and maintenance. |
25 | #[clap(subcommand)] |
26 | Jobs(JobsCommand), |
27 | @@ -107,6 +111,13 @@ fn init_config( |
28 | Ok(cfg) |
29 | } |
30 | |
31 | + fn do_migration(config: &config::Database, path: Option<String>) -> Result<(), DBError> { |
32 | + let runtime = Builder::new_current_thread().enable_all().build().unwrap(); |
33 | + let migrations_path = path.unwrap_or(config.migrations.clone()); |
34 | + runtime.block_on(migrate(&config.path, &migrations_path))?; |
35 | + Ok(()) |
36 | + } |
37 | + |
38 | fn main() -> Result<(), Box<dyn Error>> { |
39 | let args: Arguments = Arguments::parse(); |
40 | match args.subcommand { |
41 | @@ -132,13 +143,12 @@ fn main() -> Result<(), Box<dyn Error>> { |
42 | }, |
43 | Command::Migrate { migrations } => { |
44 | let cfg = init_config(args.config.as_deref(), args.level.as_deref())?; |
45 | - let runtime = Builder::new_current_thread().enable_all().build().unwrap(); |
46 | - let migrations_path = migrations.unwrap_or(cfg.database.migrations); |
47 | - runtime.block_on(migrate(&cfg.database.path, &migrations_path))?; |
48 | + do_migration(&cfg.database.clone(), migrations).unwrap(); |
49 | Ok(()) |
50 | } |
51 | - Command::Serve => { |
52 | + Command::Serve { migrations } => { |
53 | let cfg = init_config(args.config.as_deref(), args.level.as_deref())?; |
54 | + do_migration(&cfg.database.clone(), migrations).unwrap(); |
55 | // launch the job server in a separate thread |
56 | let job_config = cfg.clone(); |
57 | ThreadBuilder::new() |