Files
xamxam/lib/config.php
Théophile Gervreau-Mercier d2b3c6ca67 Major refactor
- update the structure to have monolithic setup
- updated deployments
- added live-reloading for devops
2026-02-05 20:16:19 +01:00

56 lines
1.3 KiB
PHP

<?php
/**
* Configuration for Post-ERG thesis database
* Central location for database paths and environment settings
*/
// Database paths relative to repository root
define('DB_ROOT', __DIR__ . '/..');
// Test database (used in development)
define('DB_TEST_PATH', DB_ROOT . '/database/test.db');
// Production database (used on server)
define('DB_PROD_PATH', DB_ROOT . '/database/posterg.db');
/**
* Determine which database to use
* Checks environment variable DB_ENV, defaults to auto-detection
*
* Set DB_ENV in your environment:
* - export DB_ENV=test # Force test database
* - export DB_ENV=prod # Force production database
*
* Auto-detection logic:
* - If test.db exists, use it (development)
* - Otherwise use posterg.db (production)
*/
function getDatabasePath() {
// Allow explicit override via environment variable
$env = getenv('DB_ENV');
if ($env === 'test') {
return DB_TEST_PATH;
}
if ($env === 'prod') {
return DB_PROD_PATH;
}
// Auto-detect: prefer test database if it exists
if (file_exists(DB_TEST_PATH)) {
return DB_TEST_PATH;
}
// Default to production database
return DB_PROD_PATH;
}
/**
* Check if running in test/development mode
*/
function isTestMode() {
return getDatabasePath() === DB_TEST_PATH;
}