Add migrations and user models crud
This commit is contained in:
parent
2141c992d7
commit
30be91390b
13 changed files with 473 additions and 47 deletions
|
|
@ -3,7 +3,7 @@ use askama_web::WebTemplate;
|
|||
use axum::response::{IntoResponse, Response};
|
||||
use snafu::prelude::*;
|
||||
|
||||
use crate::state::config::ConfigError;
|
||||
use crate::{models::user::UserError, state::config::ConfigError};
|
||||
|
||||
#[derive(Template, WebTemplate)]
|
||||
#[template(path = "error.html")]
|
||||
|
|
@ -21,6 +21,14 @@ pub enum AppStateError {
|
|||
ConfigError {
|
||||
source: ConfigError,
|
||||
},
|
||||
#[snafu(display("Migration Error"))]
|
||||
Migration {
|
||||
source: sea_orm::error::DbErr,
|
||||
},
|
||||
#[snafu(display("User Model Error"))]
|
||||
User {
|
||||
source: UserError,
|
||||
},
|
||||
}
|
||||
|
||||
impl IntoResponse for AppStateError {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use sea_orm::{Database, DatabaseConnection};
|
||||
use snafu::prelude::*;
|
||||
|
||||
use crate::state::config::AppConfig;
|
||||
use crate::{migrations::Migrator, state::config::AppConfig};
|
||||
use error::*;
|
||||
use sea_orm_migration::MigratorTrait;
|
||||
|
||||
pub mod config;
|
||||
pub mod error;
|
||||
|
|
@ -15,6 +16,7 @@ pub struct AppState {
|
|||
|
||||
impl AppState {
|
||||
pub async fn new() -> Result<Self, AppStateError> {
|
||||
log::info!("Load configurations...");
|
||||
let config: AppConfig = AppConfig::new().await.context(ConfigSnafu)?;
|
||||
|
||||
let db: DatabaseConnection =
|
||||
|
|
@ -22,6 +24,10 @@ impl AppState {
|
|||
.await
|
||||
.context(SqliteSnafu)?;
|
||||
|
||||
log::info!("Database Loaded at : {}", config.database_path.clone());
|
||||
|
||||
Migrator::up(&db, None).await.context(MigrationSnafu)?;
|
||||
|
||||
Ok(Self { config, db })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue