diff --git a/Cargo.lock b/Cargo.lock index 7cb0beb..acf9215 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,7 +24,7 @@ dependencies = [ [[package]] name = "altherego" -version = "0.9.5" +version = "0.9.9" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 0f8b4e1..b63c71f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "altherego" -version = "0.9.5" +version = "0.9.9" authors = ["Aleksandr Trushkin "] edition = "2018" diff --git a/src/main.rs b/src/main.rs index 4c9743f..3159e1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ mod utils; use anyhow::Result; use climate::SelfTemperature; -use env_logger; use envconfig::Envconfig; use log::{debug, info, warn}; use teloxide::{ @@ -21,8 +20,8 @@ use tokio_stream::StreamExt; use crate::repo::Storage; -const VERSION: &'static str = env!("GIT_REVISION"); -const BRANCH: &'static str = env!("GIT_BRANCH"); +const VERSION: &str = env!("GIT_REVISION"); +const BRANCH: &str = env!("GIT_BRANCH"); #[tokio::main] async fn main() { @@ -60,9 +59,10 @@ async fn run() -> anyhow::Result<()> { let settings = Settings::init_from_env().expect("reading config values"); let bot = teloxide::Bot::new(&settings.telegram_token).auto_send(); - + let migrate = std::env::args().any(|v| v == "migrate"); let repo_config = repo::SqliteConfig { source: settings.db_source, + migrate, ..Default::default() }; @@ -73,7 +73,7 @@ async fn run() -> anyhow::Result<()> { let climate_client = climate::Client::new(&settings.climate_dsn); let self_temp_client = { - let splitted: Vec<&str> = settings.hosttemp_cmd.split(" ").into_iter().collect(); + let splitted: Vec<&str> = settings.hosttemp_cmd.split(' ').into_iter().collect(); let (cmd, arg) = (splitted[0], splitted[1]); climate::SelfTemperature::new(cmd, arg) @@ -211,10 +211,7 @@ async fn handle_version(bot: AutoSend, msg: Message) -> Result<()> { Ok(()) } -async fn handle_help( - bot: AutoSend, - msg: Message, -) -> Result<()> { +async fn handle_help(bot: AutoSend, msg: Message) -> Result<()> { let chat_id = msg.chat.id; bot.send_message(chat_id, Command::descriptions().to_string()) diff --git a/src/repo.rs b/src/repo.rs index 1e14174..8b5d390 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -15,6 +15,7 @@ pub struct SqliteConfig { pub source: String, pub timeout: std::time::Duration, pub max_conns: u32, + pub migrate: bool, } impl Default for SqliteConfig { @@ -23,6 +24,7 @@ impl Default for SqliteConfig { source: ":memory:".to_string(), timeout: std::time::Duration::from_secs(10), max_conns: 2, + migrate: false, } } } @@ -54,7 +56,9 @@ impl SqliteRepo { .connect_with(opts) .await?; - // sqlx::migrate!("./db").run(&pool).await?; + if config.migrate { + sqlx::migrate!("./db").run(&pool).await?; + } sqlx::query("pragma temp_store = memory;") .execute(&pool) @@ -147,7 +151,6 @@ impl Storage for SqliteRepo { } } - async fn get_user(&self, user_id: i64) -> Result> { let result: std::result::Result = sqlx::query_as!( UserDB,