Refactor database handling to require PostgreSQL connection, removing fallback to JSON. Implement error handling for database unavailability in key files. Update .env.example to reflect mandatory DATABASE_URL for local development. Remove Firebase configuration and related code from the project.
This commit is contained in:
+13
-7
@@ -18,20 +18,26 @@ if (!$url) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$pdo = get_db_connection();
|
||||
if (!$pdo) {
|
||||
fwrite(STDERR, "Keine DB-Verbindung zu: {$url}\n");
|
||||
try {
|
||||
$pdo = require_database();
|
||||
} catch (DatabaseUnavailableException $e) {
|
||||
fwrite(STDERR, $e->getMessage() . "\n");
|
||||
fwrite(STDERR, "Prüfe: Docker läuft? docker compose -f docker-compose.dev.yml ps\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
init_db();
|
||||
|
||||
$count = (int) $pdo->query('SELECT COUNT(*) FROM recipes')->fetchColumn();
|
||||
echo "Verbindung OK. Rezepte in DB: {$count}\n";
|
||||
|
||||
if ($count > 0) {
|
||||
$stmt = $pdo->query("SELECT slug, data->'i18n'->'en'->>'title' AS title FROM recipes LIMIT 5");
|
||||
if ($count === 0) {
|
||||
echo "Hinweis: Leere DB – einmalig seeden mit: php scripts/db-seed.php\n";
|
||||
} else {
|
||||
$stmt = $pdo->query(
|
||||
"SELECT r.slug, t.title
|
||||
FROM recipes r
|
||||
LEFT JOIN recipe_translations t ON t.recipe_slug = r.slug AND t.lang = 'en'
|
||||
LIMIT 5"
|
||||
);
|
||||
echo "\nBeispiel-Zeilen:\n";
|
||||
while ($row = $stmt->fetch()) {
|
||||
echo " - {$row['slug']}: {$row['title']}\n";
|
||||
|
||||
Reference in New Issue
Block a user