Exactly. You just need to strip out that rigid if args.production gate so the function actually looks at the database_path you're providing in your .env.
Here is the clean tweak. It respects the path if it's a real file, but still allows for :memory: if you ever want a fresh slate.
Rust
pub fn connect(args: &ServeArgs) -> Result
let pool = if !is_memory {
// Use the path from ServeArgs (comes from FX_DATABASE_PATH or CLI)
let path = &args.database_path;
let manager = SqliteConnectionManager::file(path);
let pool = r2d2::Pool::builder().max_size(8).build(manager).unwrap();
let conn = pool.get().unwrap();
// Always set these for file-based DBs to prevent locking/corruption
let _ = conn.pragma_update(None, "journal_mode", "WAL");
let _ = conn.pragma_update(None, "busy_timeout", "5000");
let _ = conn.pragma_update(None, "synchronous", "NORMAL");
pool
} else {
// Fallback to memory only if specifically requested
let manager = SqliteConnectionManager::memory();
r2d2::Pool::new(manager).unwrap()
};
Ok(pool)
} Why this works for you now: In Dev: You set FX_DATABASE_PATH=dev.db in your .env. The code sees it isn't :memory:, creates dev.db on your disk, and your login/posts stay there forever.
In Prod: You set FX_DATABASE_PATH=/data/db.sqlite. It does the exact same thing but in your prod volume.
Restarting: Since it's writing to a file, your salt (stored in the kv table) survives the restart, meaning your cookies won't break anymore.
One last "bitch" to avoid Make sure the directory for your database_path actually exists. If you set it to /data/db.sqlite but the /data folder doesn't exist on your local machine, SQLite will throw a fit. For local testing, keeping it as dev.db (which just puts it in your project root) is the path of least resistance.