Skip to content

Commit 6013510

Browse files
committed
postresql logic
1 parent 51d721d commit 6013510

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

client/src/cyber-forensics-platform/.do/app.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55
github:
66
repo: xctf-io/xctf
77
branch: main
8+
build_command: npm install && npm run build
89
run_command: npm start
910
environment_slug: node-js
1011
instance_count: 1
@@ -18,7 +19,7 @@ services:
1819
scope: RUN_TIME
1920
type: SECRET
2021
- key: DATABASE_URL
21-
scope: RUN_TIME
22+
scope: RUN_AND_BUILD_TIME
2223
type: SECRET
2324
databases:
2425
- name: cyber-forensics-db

client/src/cyber-forensics-platform/src/lib/database.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
const sqlite3 = require('sqlite3').verbose();
22
const path = require('path');
33

4-
// Import PostgreSQL manager for production
5-
let PostgresDatabaseManager = null;
6-
if (process.env.NODE_ENV === 'production' && process.env.DATABASE_URL) {
7-
try {
8-
PostgresDatabaseManager = require('./database-postgres');
9-
} catch (error) {
10-
console.error('Failed to load PostgreSQL manager:', error);
11-
}
12-
}
4+
// Import PostgreSQL manager dynamically
135

146
class DatabaseManager {
157
constructor() {
@@ -352,10 +344,23 @@ let dbManager = null;
352344

353345
function getDatabase() {
354346
if (!dbManager) {
355-
// Use PostgreSQL in production, SQLite in development
356-
if (process.env.NODE_ENV === 'production' && process.env.DATABASE_URL) {
357-
dbManager = new PostgresDatabaseManager();
347+
console.log('🔍 Database selection debug:', {
348+
NODE_ENV: process.env.NODE_ENV,
349+
DATABASE_URL_exists: !!process.env.DATABASE_URL
350+
});
351+
352+
// Use PostgreSQL if DATABASE_URL is present (indicates production/cloud environment)
353+
if (process.env.DATABASE_URL) {
354+
console.log('📊 DATABASE_URL detected, using PostgreSQL database manager');
355+
try {
356+
const PostgresDatabaseManager = require('./database-postgres');
357+
dbManager = new PostgresDatabaseManager();
358+
} catch (error) {
359+
console.error('❌ Failed to load PostgreSQL manager, falling back to SQLite:', error);
360+
dbManager = new DatabaseManager();
361+
}
358362
} else {
363+
console.log('📊 No DATABASE_URL, using SQLite database manager');
359364
dbManager = new DatabaseManager();
360365
}
361366
}

0 commit comments

Comments
 (0)