improvement: show errors when writing new sqlite db

Build the sqlite writer pool first, which will provide a better error
message in the event the database is not writeable or readable.
This commit is contained in:
Greg Heartsfield 2023-01-28 14:02:20 -06:00
parent dfa6985f44
commit bdd4e43df4

View File

@ -53,6 +53,14 @@ pub struct SqliteRepo {
impl SqliteRepo {
// build all the pools needed
#[must_use] pub fn new(settings: &Settings, metrics: NostrMetrics) -> SqliteRepo {
let write_pool = build_pool(
"writer",
settings,
OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE,
1,
2,
false,
);
let maint_pool = build_pool(
"maintenance",
settings,
@ -69,14 +77,6 @@ impl SqliteRepo {
settings.database.max_conn,
true,
);
let write_pool = build_pool(
"writer",
settings,
OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE,
1,
2,
false,
);
// this is used to block new reads during critical checkpoints
let checkpoint_in_progress = Arc::new(Mutex::new(0));
@ -852,6 +852,7 @@ pub fn build_pool(
) -> SqlitePool {
let db_dir = &settings.database.data_directory;
let full_path = Path::new(db_dir).join(DB_FILE);
// small hack; if the database doesn't exist yet, that means the
// writer thread hasn't finished. Give it a chance to work. This
// is only an issue with the first time we run.