Add migrations and user models crud
This commit is contained in:
parent
2141c992d7
commit
30be91390b
13 changed files with 473 additions and 47 deletions
|
|
@ -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