fix(server): create SQLite database file if missing on first start
Build and Deploy / build-and-push (push) Successful in 1m15s
Build and Deploy / build-and-push (push) Successful in 1m15s
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,7 +65,11 @@ 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(
|
||||||
|
SqliteConnectOptions::from_str(&db_url)
|
||||||
|
.expect("invalid DATABASE_URL")
|
||||||
|
.create_if_missing(true),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.expect("failed to connect to database");
|
.expect("failed to connect to database");
|
||||||
|
|
||||||
@@ -105,7 +110,11 @@ 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(
|
||||||
|
SqliteConnectOptions::from_str(&db_url)
|
||||||
|
.expect("invalid DATABASE_URL")
|
||||||
|
.create_if_missing(true),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.expect("failed to connect to database");
|
.expect("failed to connect to database");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user