feat: run pending migrations on app start
This commit is contained in:
parent
01a48c0840
commit
f6034d8433
@ -7,18 +7,21 @@ mod server;
|
|||||||
mod query;
|
mod query;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod internationalization;
|
mod internationalization;
|
||||||
|
mod migrations;
|
||||||
|
|
||||||
use components::app::App;
|
use components::app::App;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use dioxus_logger::tracing::{info, Level};
|
use dioxus_logger::tracing::{info, Level};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
dioxus_logger::init(Level::INFO).expect("failed to initialize logger");
|
dioxus_logger::init(Level::INFO).expect("Failed to initialize the logger.");
|
||||||
info!("starting app");
|
|
||||||
|
|
||||||
|
info!("Running migrations.");
|
||||||
|
migrations::run_migrations().expect("Failed to run migrations.");
|
||||||
|
|
||||||
|
info!("Starting app.");
|
||||||
let cfg = server_only!(
|
let cfg = server_only!(
|
||||||
dioxus::fullstack::Config::new().addr(std::net::SocketAddr::from(([0, 0, 0, 0], 8000)))
|
dioxus::fullstack::Config::new().addr(std::net::SocketAddr::from(([0, 0, 0, 0], 8000)))
|
||||||
);
|
);
|
||||||
|
|
||||||
LaunchBuilder::fullstack().with_cfg(cfg).launch(App);
|
LaunchBuilder::fullstack().with_cfg(cfg).launch(App);
|
||||||
}
|
}
|
||||||
|
12
src/migrations/mod.rs
Normal file
12
src/migrations/mod.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
|
const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
|
||||||
|
|
||||||
|
pub(crate) fn run_migrations() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
||||||
|
let mut connection = crate::server::database_connection::establish_database_connection()?;
|
||||||
|
|
||||||
|
connection.run_pending_migrations(MIGRATIONS)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
mod database_connection;
|
pub(crate) mod database_connection;
|
||||||
pub(crate) mod projects;
|
pub(crate) mod projects;
|
||||||
pub(crate) mod tasks;
|
pub(crate) mod tasks;
|
||||||
pub(crate) mod subtasks;
|
pub(crate) mod subtasks;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user