Merge pull request #3 from stevedylandev/fix/parcels-db-path 6134ee0d
fix: issue with parcels db path
Steve Simkins · 2026-04-02 23:30 4 file(s) · +9 −18
apps/parcels/.env.example +0 −1
1 1
APP_PASSWORD=changeme
2 -
PARCELS_DB_PATH=parcels.db
3 2
USPS_CLIENT_ID=your_client_id_here
4 3
USPS_CLIENT_SECRET=your_client_secret_here
5 4
PORT=3000
apps/parcels/Cargo.toml +1 −1
1 1
[package]
2 2
name = "parcels"
3 -
version = "0.1.2"
3 +
version = "0.1.3"
4 4
edition = "2024"
5 5
description = "Minimal package tracking"
6 6
license = "MIT"
apps/parcels/src/db.rs +7 −14
59 59
60 60
// ── Pool Setup ──────────────────────────────────────────────────────────────
61 61
62 -
pub fn database_path() -> String {
63 -
    std::env::var("PARCELS_DB_PATH").unwrap_or_else(|_| "parcels.db".to_string())
64 -
}
65 -
66 -
pub fn init_db(path: &str) -> Result<Db, DbError> {
67 -
    if let Some(parent) = std::path::Path::new(path).parent() {
68 -
        if parent != std::path::Path::new("") {
69 -
            std::fs::create_dir_all(parent).ok();
70 -
        }
71 -
    }
72 -
    let conn = Connection::open(path)?;
73 -
    conn.execute_batch("PRAGMA journal_mode=WAL; PRAGMA foreign_keys=ON;")?;
62 +
pub fn init_db() -> Db {
63 +
    let path = "parcels.db";
64 +
    let conn = Connection::open(path).expect("Failed to open database");
65 +
    conn.execute_batch("PRAGMA journal_mode=WAL; PRAGMA foreign_keys=ON;")
66 +
        .expect("Failed to set PRAGMAs");
74 67
    conn.execute_batch("
75 68
        CREATE TABLE IF NOT EXISTS packages (
76 69
            id                INTEGER PRIMARY KEY AUTOINCREMENT,
99 92
            token      TEXT NOT NULL UNIQUE,
100 93
            expires_at TEXT NOT NULL
101 94
        );
102 -
    ")?;
103 -
    Ok(Arc::new(Mutex::new(conn)))
95 +
    ").expect("Failed to create tables");
96 +
    Arc::new(Mutex::new(conn))
104 97
}
105 98
106 99
// ── Package Queries ─────────────────────────────────────────────────────────
apps/parcels/src/main.rs +1 −2
345 345
    tracing_subscriber::fmt::init();
346 346
    use std::env;
347 347
348 -
    let database_url = db::database_path();
349 348
    let app_password = env::var("APP_PASSWORD").expect("APP_PASSWORD must be set");
350 349
    let usps_client_id = env::var("USPS_CLIENT_ID").expect("USPS_CLIENT_ID must be set");
351 350
    let usps_client_secret = env::var("USPS_CLIENT_SECRET").expect("USPS_CLIENT_SECRET must be set");
359 358
        .map(|v| v.eq_ignore_ascii_case("true"))
360 359
        .unwrap_or(false);
361 360
362 -
    let db = db::init_db(&database_url).expect("Failed to open database");
361 +
    let db = db::init_db();
363 362
364 363
    let state = Arc::new(AppState {
365 364
        db,