diff options
Diffstat (limited to '')
-rw-r--r-- | src/main.rs | 31 | ||||
-rw-r--r-- | src/posts/article.rs | 0 | ||||
-rw-r--r-- | src/posts/mod.rs | 0 | ||||
-rw-r--r-- | src/posts/note.rs | 0 |
4 files changed, 30 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 1850b01..8ad4bf4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,41 @@ +use rocket::fairing::{self, AdHoc}; use rocket::fs::{relative, FileServer}; use rocket::http::Status; -use rocket::Request; use rocket::State; +use rocket::{Build, Request, Rocket}; +use rocket_db_pools::sqlx::{self, database}; +use rocket_db_pools::{Connection, Database}; use rocket_dyn_templates::{context, Template}; use std::borrow::Cow; mod scrobbles; mod skweets; +#[derive(Database)] +#[database("blossom")] +struct Blossom(sqlx::SqlitePool); + +async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result { + match Blossom::fetch(&rocket) { + Some(db) => match sqlx::migrate!().run(&**db).await { + Ok(_) => Ok(rocket), + Err(e) => { + error!("failed to init blossom database: {}", e); + Err(rocket) + } + }, + None => Err(rocket), + } +} + +fn stage() -> AdHoc { + AdHoc::on_ignite("blossom database stage", |rocket| async { + rocket + .attach(Blossom::init()) + .attach(AdHoc::try_on_ignite("database migrations", run_migrations)) + }) +} + struct Clients { listenbrainz: listenbrainz::raw::Client, skinnyverse: mastodon_async::Mastodon, @@ -62,6 +90,7 @@ async fn main() -> Result<(), rocket::Error> { skinny_data.base = Cow::from("https://skinnyver.se"); let _rocket = rocket::build() + .attach(stage()) .manage(Clients { listenbrainz: listenbrainz::raw::Client::new(), skinnyverse: mastodon_async::Mastodon::from(skinny_data), diff --git a/src/posts/article.rs b/src/posts/article.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/posts/article.rs diff --git a/src/posts/mod.rs b/src/posts/mod.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/posts/mod.rs diff --git a/src/posts/note.rs b/src/posts/note.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/posts/note.rs |