diff --git a/Cargo.lock b/Cargo.lock index 31dd819..dc34c6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,6 +183,16 @@ dependencies = [ "syn 1.0.16", ] +[[package]] +name = "diesel_migrations" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf3cde8413353dc7f5d72fa8ce0b99a560a359d2c5ef1e5817ca731cd9008f4c" +dependencies = [ + "migrations_internals", + "migrations_macros", +] + [[package]] name = "dotenv" version = "0.15.0" @@ -654,6 +664,27 @@ version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +[[package]] +name = "migrations_internals" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8089920229070f914b9ce9b07ef60e175b2b9bc2d35c3edd8bf4433604e863b9" +dependencies = [ + "diesel", +] + +[[package]] +name = "migrations_macros" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719ef0bc7f531428764c9b70661c14abd50a7f3d21f355752d9985aa21251c9e" +dependencies = [ + "migrations_internals", + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", +] + [[package]] name = "mime" version = "0.2.6" @@ -1800,6 +1831,7 @@ version = "0.1.0" dependencies = [ "chrono", "diesel", + "diesel_migrations", "dotenv", "futures", "md5", diff --git a/Cargo.toml b/Cargo.toml index 6d21d44..0bc40e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,4 @@ dotenv = "0.15.0" uuid = "0.6" chrono = "0.4.11" md5 = "0.7.0" +diesel_migrations = "1.4.0" diff --git a/diesel.toml b/diesel.toml new file mode 100644 index 0000000..92267c8 --- /dev/null +++ b/diesel.toml @@ -0,0 +1,5 @@ +# For documentation on how to configure this file, +# see diesel.rs/guides/configuring-diesel-cli + +[print_schema] +file = "src/schema.rs" diff --git a/src/main.rs b/src/main.rs index e43c50b..3fee7e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,8 @@ extern crate diesel; use std::env; +#[macro_use] +extern crate diesel_migrations; use futures::StreamExt; use telegram_bot::*; @@ -13,8 +15,13 @@ mod process; mod scheduler; mod schema; +embed_migrations!(); + #[tokio::main] async fn main() -> Result<(), Error> { + let db_connection = database::establish_connection(); + embedded_migrations::run(&db_connection).unwrap(); + let token = env::var("TELEGRAM_BOT_TOKEN").expect("TELEGRAM_BOT_TOKEN not set"); let api = Api::new(&token);