allow to migrate tables
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -24,7 +24,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "altherego"
|
name = "altherego"
|
||||||
version = "0.9.5"
|
version = "0.9.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "altherego"
|
name = "altherego"
|
||||||
version = "0.9.5"
|
version = "0.9.9"
|
||||||
authors = ["Aleksandr Trushkin <aleksandr.trushkin@rt.ru>"]
|
authors = ["Aleksandr Trushkin <aleksandr.trushkin@rt.ru>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|||||||
15
src/main.rs
15
src/main.rs
@ -6,7 +6,6 @@ mod utils;
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use climate::SelfTemperature;
|
use climate::SelfTemperature;
|
||||||
use env_logger;
|
|
||||||
use envconfig::Envconfig;
|
use envconfig::Envconfig;
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
use teloxide::{
|
use teloxide::{
|
||||||
@ -21,8 +20,8 @@ use tokio_stream::StreamExt;
|
|||||||
|
|
||||||
use crate::repo::Storage;
|
use crate::repo::Storage;
|
||||||
|
|
||||||
const VERSION: &'static str = env!("GIT_REVISION");
|
const VERSION: &str = env!("GIT_REVISION");
|
||||||
const BRANCH: &'static str = env!("GIT_BRANCH");
|
const BRANCH: &str = env!("GIT_BRANCH");
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
@ -60,9 +59,10 @@ async fn run() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let settings = Settings::init_from_env().expect("reading config values");
|
let settings = Settings::init_from_env().expect("reading config values");
|
||||||
let bot = teloxide::Bot::new(&settings.telegram_token).auto_send();
|
let bot = teloxide::Bot::new(&settings.telegram_token).auto_send();
|
||||||
|
let migrate = std::env::args().any(|v| v == "migrate");
|
||||||
let repo_config = repo::SqliteConfig {
|
let repo_config = repo::SqliteConfig {
|
||||||
source: settings.db_source,
|
source: settings.db_source,
|
||||||
|
migrate,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ async fn run() -> anyhow::Result<()> {
|
|||||||
let climate_client = climate::Client::new(&settings.climate_dsn);
|
let climate_client = climate::Client::new(&settings.climate_dsn);
|
||||||
|
|
||||||
let self_temp_client = {
|
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]);
|
let (cmd, arg) = (splitted[0], splitted[1]);
|
||||||
|
|
||||||
climate::SelfTemperature::new(cmd, arg)
|
climate::SelfTemperature::new(cmd, arg)
|
||||||
@ -211,10 +211,7 @@ async fn handle_version(bot: AutoSend<Bot>, msg: Message) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_help(
|
async fn handle_help(bot: AutoSend<Bot>, msg: Message) -> Result<()> {
|
||||||
bot: AutoSend<Bot>,
|
|
||||||
msg: Message,
|
|
||||||
) -> Result<()> {
|
|
||||||
let chat_id = msg.chat.id;
|
let chat_id = msg.chat.id;
|
||||||
|
|
||||||
bot.send_message(chat_id, Command::descriptions().to_string())
|
bot.send_message(chat_id, Command::descriptions().to_string())
|
||||||
|
|||||||
@ -15,6 +15,7 @@ pub struct SqliteConfig {
|
|||||||
pub source: String,
|
pub source: String,
|
||||||
pub timeout: std::time::Duration,
|
pub timeout: std::time::Duration,
|
||||||
pub max_conns: u32,
|
pub max_conns: u32,
|
||||||
|
pub migrate: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SqliteConfig {
|
impl Default for SqliteConfig {
|
||||||
@ -23,6 +24,7 @@ impl Default for SqliteConfig {
|
|||||||
source: ":memory:".to_string(),
|
source: ":memory:".to_string(),
|
||||||
timeout: std::time::Duration::from_secs(10),
|
timeout: std::time::Duration::from_secs(10),
|
||||||
max_conns: 2,
|
max_conns: 2,
|
||||||
|
migrate: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,7 +56,9 @@ impl SqliteRepo {
|
|||||||
.connect_with(opts)
|
.connect_with(opts)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// sqlx::migrate!("./db").run(&pool).await?;
|
if config.migrate {
|
||||||
|
sqlx::migrate!("./db").run(&pool).await?;
|
||||||
|
}
|
||||||
|
|
||||||
sqlx::query("pragma temp_store = memory;")
|
sqlx::query("pragma temp_store = memory;")
|
||||||
.execute(&pool)
|
.execute(&pool)
|
||||||
@ -147,7 +151,6 @@ impl Storage for SqliteRepo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn get_user(&self, user_id: i64) -> Result<Option<UserDB>> {
|
async fn get_user(&self, user_id: i64) -> Result<Option<UserDB>> {
|
||||||
let result: std::result::Result<UserDB, sqlx::Error> = sqlx::query_as!(
|
let result: std::result::Result<UserDB, sqlx::Error> = sqlx::query_as!(
|
||||||
UserDB,
|
UserDB,
|
||||||
|
|||||||
Reference in New Issue
Block a user