From 4e8127b5c8190d5223fd0046682473a35f72ba98 Mon Sep 17 00:00:00 2001 From: Josh Date: Sat, 13 Sep 2025 16:01:48 +0000 Subject: [PATCH] user_profile sqlite3 cleanup --- backend/server2.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/backend/server2.js b/backend/server2.js index 6e5835e..3226149 100755 --- a/backend/server2.js +++ b/backend/server2.js @@ -45,7 +45,9 @@ const USER_PROFILE_DB_PATH = path.join(ROOT_DIR, 'user_profile.db'); const DB_POOL_SIZE = 6; const API_BASE = (process.env.APTIVA_INTERNAL_API || 'http://server1:5000').replace(/\/+$/, ''); -for (const p of [CIP_TO_SOC_PATH, INSTITUTION_DATA_PATH, SALARY_DB_PATH, USER_PROFILE_DB_PATH]) { +const REQUIRED_FILES = [CIP_TO_SOC_PATH, INSTITUTION_DATA_PATH, SALARY_DB_PATH]; +if (process.env.NODE_ENV !== 'production') REQUIRED_FILES.push(USER_PROFILE_DB_PATH); +for (const p of REQUIRED_FILES) { if (!fs.existsSync(p)) { console.error(`FATAL Required data file not found → ${p}`); process.exit(1); @@ -535,17 +537,18 @@ async function initDatabases() { AND (AREA_TITLE = ? OR AREA_TITLE = 'U.S.') `); - // 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') { + // In prod, user_profile is MySQL; do not open a SQLite file. + // Allow opt-in via USE_SQLITE_USER_PROFILE=1 for dev/local only. + if (process.env.USE_SQLITE_USER_PROFILE === '1') { userProfileDb = await open({ - filename: USER_PROFILE_DB_PATH, - driver : sqlite3.Database + filename: `file:${USER_PROFILE_DB_PATH}?mode=ro`, + driver : sqlite3.Database, + mode : sqlite3.OPEN_READONLY | sqlite3.OPEN_URI }); - console.log('✅ Connected to user_profile.db (sqlite, dev)'); + console.log('✅ Connected to user_profile.db (sqlite, ro)'); } else { userProfileDb = null; - console.log('ℹ️ user_profile via MySQL pool (no SQLite open in prod)'); + console.log('ℹ️ user_profile via MySQL pool (SQLite disabled)'); } } catch (err) { console.error('❌ DB init failed →', err);