Fix SQLite create_if_missing so the database is auto-created on first run
CI / Build, lint & test (push) Failing after 1m20s
CI / Build, lint & test (push) Failing after 1m20s
Previously the binary failed with "unable to open database file" (SQLite code 14) when no openfut.db existed yet. Using SqliteConnectOptions with create_if_missing(true) tells SQLite to create the file if absent. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +1,19 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use sqlx::{sqlite::SqlitePoolOptions, SqlitePool};
|
use sqlx::{
|
||||||
|
sqlite::{SqliteConnectOptions, SqlitePoolOptions},
|
||||||
|
SqlitePool,
|
||||||
|
};
|
||||||
|
use std::str::FromStr;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
pub type Pool = SqlitePool;
|
pub type Pool = SqlitePool;
|
||||||
|
|
||||||
pub async fn init_pool(database_url: &str) -> Result<Pool> {
|
pub async fn init_pool(database_url: &str) -> Result<Pool> {
|
||||||
info!("Connecting to database: {}", database_url);
|
info!("Connecting to database: {}", database_url);
|
||||||
|
let opts = SqliteConnectOptions::from_str(database_url)?.create_if_missing(true);
|
||||||
let pool = SqlitePoolOptions::new()
|
let pool = SqlitePoolOptions::new()
|
||||||
.max_connections(5)
|
.max_connections(5)
|
||||||
.connect(database_url)
|
.connect_with(opts)
|
||||||
.await?;
|
.await?;
|
||||||
sqlx::query("PRAGMA journal_mode=WAL")
|
sqlx::query("PRAGMA journal_mode=WAL")
|
||||||
.execute(&pool)
|
.execute(&pool)
|
||||||
|
|||||||
Reference in New Issue
Block a user