Skip to content

Commit 678818a

Browse files
committed
apply database migrations before initializing on-database filesystem
this allows populating the in-database filesystem in migrations fixes #461
1 parent a7b998b commit 678818a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/filesystem.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub(crate) struct DbFsQueries {
145145

146146
impl DbFsQueries {
147147
async fn init(db: &Database) -> anyhow::Result<Self> {
148+
log::debug!("Initializing database filesystem queries");
148149
let db_kind = db.connection.any_kind();
149150
Ok(Self {
150151
was_modified: Self::make_was_modified_query(db, db_kind).await?,

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ pub struct AppState {
3838

3939
impl AppState {
4040
pub async fn init(config: &AppConfig) -> anyhow::Result<Self> {
41-
// Connect to the database
4241
let db = Database::init(config).await?;
42+
Self::init_with_db(config, db).await
43+
}
44+
pub async fn init_with_db(config: &AppConfig, db: Database) -> anyhow::Result<Self> {
4345
let all_templates = AllTemplates::init(config)?;
4446
let mut sql_file_cache = FileCache::new();
4547
let file_system = FileSystem::init(&config.web_root, &db).await;

src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use std::fmt::Write;
22

33
use sqlpage::{
44
app_config::{self, AppConfig},
5-
webserver, AppState,
5+
webserver::{self, Database},
6+
AppState,
67
};
78

89
#[actix_web::main]
@@ -16,8 +17,9 @@ async fn main() {
1617

1718
async fn start() -> anyhow::Result<()> {
1819
let app_config = app_config::load()?;
19-
let state = AppState::init(&app_config).await?;
20-
webserver::database::migrations::apply(&app_config, &state.db).await?;
20+
let db = Database::init(&app_config).await?;
21+
webserver::database::migrations::apply(&app_config, &db).await?;
22+
let state = AppState::init_with_db(&app_config, db).await?;
2123
log::debug!("Starting server...");
2224
let (r, _) = tokio::join!(
2325
webserver::http::run_server(&app_config, state),

0 commit comments

Comments
 (0)