mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-07 03:29:19 +02:00
Major refactor
- update the structure to have monolithic setup - updated deployments - added live-reloading for devops
This commit is contained in:
55
lib/config.php
Normal file
55
lib/config.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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;
|
||||
}
|
||||
Reference in New Issue
Block a user