Commit
Author: Kevin Schoon [me@kevinschoon.com]
Hash: 3496fce5a7dc2b1b2c5dad74f1db37e9469c8396
Timestamp: Wed, 17 Apr 2024 08:51:40 +0000 (1 year ago)

+16 -3 +/-3 browse
update migrations path default and make it configurable
1diff --git a/ayllu/src/config.rs b/ayllu/src/config.rs
2index da52ef2..3e88b9e 100644
3--- a/ayllu/src/config.rs
4+++ b/ayllu/src/config.rs
5 @@ -93,6 +93,9 @@ pub struct Database {
6 pub path: String,
7 #[serde(default = "Database::migrate_default")]
8 pub migrate: bool,
9+ #[serde(default = "Database::migrations_default")]
10+ /// path to migrations
11+ pub migrations: String
12 }
13
14 impl Database {
15 @@ -105,6 +108,10 @@ impl Database {
16 fn migrate_default() -> bool {
17 true
18 }
19+
20+ fn migrations_default() -> String {
21+ String::from("/usr/lib/ayllu/migrations/ayllu")
22+ }
23 }
24
25 #[derive(Deserialize, Serialize, Clone, Debug)]
26 diff --git a/ayllu/src/main.rs b/ayllu/src/main.rs
27index 0131ad1..ce4afb6 100644
28--- a/ayllu/src/main.rs
29+++ b/ayllu/src/main.rs
30 @@ -59,7 +59,11 @@ enum Command {
31 #[clap(subcommand)]
32 Config(ConfigCommand),
33 /// Perform database migration.
34- Migrate,
35+ Migrate {
36+ #[clap(short, long)]
37+ /// optional path to migrations directory
38+ migrations: Option<String>,
39+ },
40 /// Launch the main web server.
41 Serve,
42 /// Offline indexing and maintenance.
43 @@ -126,10 +130,11 @@ fn main() -> Result<(), Box<dyn Error>> {
44 Ok(())
45 }
46 },
47- Command::Migrate => {
48+ Command::Migrate { migrations } => {
49 let cfg = init_config(args.config.as_deref(), args.level.as_deref())?;
50 let runtime = Builder::new_current_thread().enable_all().build().unwrap();
51- runtime.block_on(migrate(&cfg.database.path, "./migrations"))?;
52+ let migrations_path = migrations.unwrap_or(cfg.database.migrations);
53+ runtime.block_on(migrate(&cfg.database.path, &migrations_path))?;
54 Ok(())
55 }
56 Command::Serve => {
57 diff --git a/containers/base/Containerfile b/containers/base/Containerfile
58index 5bd0f9f..3f4c7a0 100644
59--- a/containers/base/Containerfile
60+++ b/containers/base/Containerfile
61 @@ -40,6 +40,7 @@ RUN apk add \
62 COPY --from=build --chown=0:0 /home/builder/src/target/release/ayllu /usr/bin/
63 COPY --from=build --chown=0:0 /home/builder/src/target/release/quipu /usr/bin/
64 COPY --from=build --chown=0:0 /home/builder/src/ayllu/themes /usr/lib/ayllu/themes
65+ COPY --from=build --chown=0:0 /home/builder/src/ayllu/migrations /usr/lib/ayllu/migrations/ayllu
66
67 RUN adduser -D -s /bin/sh -h /home/ayllu ayllu
68