This commit is contained in:
Lizandro Guarnizo
2026-06-09 16:35:12 -05:00
parent b9d019d6de
commit 80f334d5bd
2 changed files with 54 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
$host = getenv('DB_HOST') ?: 'localhost';
$port = getenv('DB_PORT') ?: '5432';
$dbname = getenv('DB_DATABASE') ?: 'usite_heidivers';
$user = getenv('DB_USERNAME') ?: 'usite_heidivers';
$pass = getenv('DB_PASSWORD') ?: '';
$dsn = "pgsql:host=$host;port=$port;dbname=$dbname";
try {
$pdo = new PDO($dsn, $user, $pass, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
} catch (PDOException $e) {
fwrite(STDERR, "DB not available: {$e->getMessage()}\n");
exit(0);
}
$tables = $pdo->query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")->fetchAll(PDO::FETCH_COLUMN);
if (!in_array('sessions', $tables)) {
$pdo->exec("CREATE TABLE sessions (
id VARCHAR(255) PRIMARY KEY,
user_id BIGINT NULL,
ip_address VARCHAR(45) NULL,
user_agent TEXT NULL,
payload TEXT NOT NULL,
last_activity INTEGER NOT NULL
)");
$pdo->exec("CREATE INDEX sessions_user_id_index ON sessions (user_id)");
$pdo->exec("CREATE INDEX sessions_last_activity_index ON sessions (last_activity)");
echo "Created sessions table\n";
}
if (!in_array('cache', $tables)) {
$pdo->exec("CREATE TABLE cache (
key VARCHAR(255) PRIMARY KEY,
value TEXT NOT NULL,
expiration INTEGER NOT NULL
)");
echo "Created cache table\n";
}
if (!in_array('cache_locks', $tables)) {
$pdo->exec("CREATE TABLE cache_locks (
key VARCHAR(255) PRIMARY KEY,
owner VARCHAR(255) NOT NULL,
expiration INTEGER NOT NULL
)");
echo "Created cache_locks table\n";
}
echo "Tables check complete\n";
+3
View File
@@ -17,4 +17,7 @@ fi
chmod -R 775 storage bootstrap/cache
chown -R www-data:www-data storage bootstrap/cache
# Create missing DB tables (sessions, cache) without breaking existing data
php /app/docker/ensure-tables.php 2>/dev/null || true
exec "$@"