Files
flixcooks-website/scripts/db-check.php
T

46 lines
1.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Kurzer Verbindungstest zur lokalen Postgres-Instanz.
* Aufruf (im Projektroot):
* php scripts/db-check.php
*/
require_once dirname(__DIR__) . '/config.php';
require_once dirname(__DIR__) . '/helpers.php';
if (!extension_loaded('pdo_pgsql')) {
fwrite(STDERR, "PHP-Extension pdo_pgsql fehlt. z. B.: sudo apt install php-pgsql\n");
exit(1);
}
$url = getenv('DATABASE_URL');
if (!$url) {
fwrite(STDERR, "DATABASE_URL ist nicht gesetzt. In .env eintragen (siehe .env.example).\n");
exit(1);
}
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);
}
$count = (int) $pdo->query('SELECT COUNT(*) FROM recipes')->fetchColumn();
echo "Verbindung OK. Rezepte in DB: {$count}\n";
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";
}
}