fix(server): create SQLite database file if missing on first start
SqlitePool::connect defaults create_if_missing=false in SQLx 0.8, causing SQLITE_CANTOPEN (error 14) when the PVC is empty on first deploy. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,9 +32,10 @@
|
|||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use solitaire_server::{build_router, AppState};
|
use solitaire_server::{build_router, AppState};
|
||||||
use sqlx::SqlitePool;
|
use sqlx::{sqlite::SqliteConnectOptions, SqlitePool};
|
||||||
use std::{
|
use std::{
|
||||||
io::{self, BufRead},
|
io::{self, BufRead},
|
||||||
|
str::FromStr,
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -64,9 +65,13 @@ async fn main() {
|
|||||||
async fn run_reset_password(username: &str) {
|
async fn run_reset_password(username: &str) {
|
||||||
let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||||||
|
|
||||||
let pool = SqlitePool::connect(&db_url)
|
let pool = SqlitePool::connect_with(
|
||||||
.await
|
SqliteConnectOptions::from_str(&db_url)
|
||||||
.expect("failed to connect to database");
|
.expect("invalid DATABASE_URL")
|
||||||
|
.create_if_missing(true),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("failed to connect to database");
|
||||||
|
|
||||||
sqlx::migrate!("./migrations")
|
sqlx::migrate!("./migrations")
|
||||||
.run(&pool)
|
.run(&pool)
|
||||||
@@ -105,9 +110,13 @@ async fn run_server() {
|
|||||||
.parse()
|
.parse()
|
||||||
.expect("SERVER_PORT must be a valid port number");
|
.expect("SERVER_PORT must be a valid port number");
|
||||||
|
|
||||||
let pool = SqlitePool::connect(&db_url)
|
let pool = SqlitePool::connect_with(
|
||||||
.await
|
SqliteConnectOptions::from_str(&db_url)
|
||||||
.expect("failed to connect to database");
|
.expect("invalid DATABASE_URL")
|
||||||
|
.create_if_missing(true),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("failed to connect to database");
|
||||||
|
|
||||||
sqlx::migrate!("./migrations")
|
sqlx::migrate!("./migrations")
|
||||||
.run(&pool)
|
.run(&pool)
|
||||||
|
|||||||
Reference in New Issue
Block a user