From 6578d3c856be0ade4d20a0666f08a1d49f8c2e56 Mon Sep 17 00:00:00 2001 From: Josh Date: Sat, 13 Sep 2025 15:47:08 +0000 Subject: [PATCH] changed server2 user_profile.db to remove sqlite connection --- backend/server2.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/backend/server2.js b/backend/server2.js index 049c5fa..6e5835e 100755 --- a/backend/server2.js +++ b/backend/server2.js @@ -503,17 +503,18 @@ let userProfileDb; async function initDatabases() { try { + // Open salary DB as an immutable, read-only URI so SQLite never touches -wal/-shm/-journal. + // Requires OPEN_URI flag in addition to OPEN_READONLY. + const SALARY_DB_URI = `file:${SALARY_DB_PATH}?immutable=1&mode=ro`; dbSqlite = await open({ - filename: SALARY_DB_PATH, + filename: SALARY_DB_URI, driver : sqlite3.Database, - mode : sqlite3.OPEN_READONLY + mode : sqlite3.OPEN_READONLY | sqlite3.OPEN_URI }); - console.log('✅ Connected to salary_info.db'); - // Light PRAGMAs safe for read-only workload + console.log('✅ Connected to salary_info.db (immutable, ro)'); + // Read-only safe PRAGMAs (no write state). journal_mode/synchronous removed. await dbSqlite.exec(` PRAGMA busy_timeout=4000; - PRAGMA journal_mode=OFF; - PRAGMA synchronous=OFF; PRAGMA temp_store=MEMORY; `); // One prepared statement: regional (param) + national in a single scan @@ -534,11 +535,18 @@ async function initDatabases() { AND (AREA_TITLE = ? OR AREA_TITLE = 'U.S.') `); - userProfileDb = await open({ - filename: USER_PROFILE_DB_PATH, - driver : sqlite3.Database - }); - console.log('✅ Connected to user_profile.db'); + // In prod, user_profile is MySQL; do not try to open a SQLite file here. + // Leave dev behavior untouched: only open SQLite if clearly running non-prod. + if (process.env.NODE_ENV !== 'production') { + userProfileDb = await open({ + filename: USER_PROFILE_DB_PATH, + driver : sqlite3.Database + }); + console.log('✅ Connected to user_profile.db (sqlite, dev)'); + } else { + userProfileDb = null; + console.log('ℹ️ user_profile via MySQL pool (no SQLite open in prod)'); + } } catch (err) { console.error('❌ DB init failed →', err); process.exit(1);