Skip to content

Commit 40f274e

Browse files
committed
Check database filesystem table before preparing queries
1 parent a467319 commit 40f274e

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/filesystem.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use anyhow::Context;
66
use chrono::{DateTime, Utc};
77
use sqlx::any::{AnyStatement, AnyTypeInfo};
88
use sqlx::postgres::types::PgTimeTz;
9-
use sqlx::{Postgres, Statement, Type};
9+
use sqlx::{Executor, Postgres, Statement, Type};
1010
use std::fmt::Write;
1111
use std::io::ErrorKind;
1212
use std::path::{Component, Path, PathBuf};
@@ -267,13 +267,23 @@ impl DbFsQueries {
267267

268268
async fn init(db: &Database) -> anyhow::Result<Self> {
269269
log::debug!("Initializing database filesystem queries");
270+
Self::check_table_available(db).await?;
270271
Ok(Self {
271272
was_modified: Self::make_was_modified_query(db).await?,
272273
read_file: Self::make_read_file_query(db).await?,
273274
exists: Self::make_exists_query(db).await?,
274275
})
275276
}
276277

278+
async fn check_table_available(db: &Database) -> anyhow::Result<()> {
279+
db.connection
280+
.execute("SELECT 1 FROM sqlpage_files WHERE 1 = 0")
281+
.await
282+
.map(|_| ())
283+
.context("Unable to access sqlpage_files")?;
284+
Ok(())
285+
}
286+
277287
async fn make_was_modified_query(db: &Database) -> anyhow::Result<AnyStatement<'static>> {
278288
let was_modified_query = format!(
279289
"SELECT 1 from sqlpage_files WHERE last_modified >= {} AND path = {}",

0 commit comments

Comments
 (0)