mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
fix(config): auto-route test.db locally, posterg.db on production
- config.php: getDatabasePath() detects php built-in CLI server (php_sapi_name() === 'cli-server') and routes to test.db; all other SAPIs (nginx/fpm) get posterg.db. DB_ENV env-var still overrides either way. - migrate.sh: auto-initialise the target DB from storage/schema.sql when the file is absent or has no tables yet. Existing DBs with data are left completely untouched (table_count check, no re-run of schema on populated DB). Idempotent: safe to run repeatedly. - justfile: serve still calls migrate (which now handles init too), no DB_ENV prefix needed since sapi detection handles routing.
This commit is contained in:
@@ -63,9 +63,13 @@ migrate_db() {
|
||||
local db="$1"
|
||||
local label="$2"
|
||||
|
||||
if [ ! -f "$db" ]; then
|
||||
echo " [$label] database not found, skipping: $db"
|
||||
return
|
||||
# Auto-create from schema only when the file is absent or truly empty (no tables)
|
||||
local table_count
|
||||
table_count=$(sqlite3 "$db" "SELECT COUNT(*) FROM sqlite_master WHERE type='table';" 2>/dev/null || echo 0)
|
||||
if [ "$table_count" -eq 0 ]; then
|
||||
echo " [$label] initialising from schema…"
|
||||
sqlite3 "$db" < "$REPO_ROOT/storage/schema.sql"
|
||||
echo " [$label] schema applied."
|
||||
fi
|
||||
|
||||
# Ensure tracking table exists
|
||||
|
||||
Reference in New Issue
Block a user