diff --git a/app/page.tsx b/app/page.tsx index c31ae9d..c2d2822 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -5,7 +5,7 @@ export default function Home() { const issRow = db.prepare(` SELECT pass_time, end_time FROM iss_passes - WHERE datetime(end_time) > datetime('now') + WHERE unixepoch(end_time) > unixepoch('now') ORDER BY datetime(pass_time) ASC LIMIT 1 `).get() as { pass_time: string, end_time: string } | undefined; diff --git a/lib/db.ts b/lib/db.ts index 985e69e..4482e9b 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -3,15 +3,18 @@ import path from 'path'; import fs from 'fs'; const isProduction = process.env.NODE_ENV === 'production'; -const dbDir = isProduction - ? '/app/data' - : path.resolve(process.cwd(), 'data'); +const dbPath = isProduction + ? '/app/data/space_data.db' + : path.resolve(process.cwd(), 'data/space_data.db'); +console.log(`[DB] Using database at: ${dbPath}`); + +// Ensure the directory exists (helps locally) +const dbDir = path.dirname(dbPath); if (!fs.existsSync(dbDir)) { fs.mkdirSync(dbDir, { recursive: true }); } -const dbPath = path.join(dbDir, 'space_data.db'); const db = new Database(dbPath); db.exec(` @@ -30,6 +33,11 @@ db.exec(` ); `); - +try { + const count = db.prepare("SELECT count(*) as total FROM global_events").get() as { total: number }; + console.log(`[DB] Connected. Found ${count.total} events.`); +} catch (e) { + console.log(`[DB] Table not ready yet or empty.`); +} export default db; \ No newline at end of file