From 80f334d5bd5f606739bf527a00256d00e7d6214e Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 9 Jun 2026 16:35:12 -0500 Subject: [PATCH] up --- docker/ensure-tables.php | 51 ++++++++++++++++++++++++++++++++++++++++ docker/entrypoint.sh | 3 +++ 2 files changed, 54 insertions(+) create mode 100644 docker/ensure-tables.php diff --git a/docker/ensure-tables.php b/docker/ensure-tables.php new file mode 100644 index 0000000..ae31d6d --- /dev/null +++ b/docker/ensure-tables.php @@ -0,0 +1,51 @@ + 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"; diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 916e628..5dd269c 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -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 "$@"