Fix: dubbele SIGTERM/SIGINT verwijderd (closeSignal blijft)

This commit is contained in:
root
2026-05-25 18:45:42 +00:00
parent c0b33c2144
commit d5fb1404e3
2 changed files with 13 additions and 9 deletions
+12 -4
View File
@@ -32,8 +32,10 @@ function migrateSchema() {
hours INTEGER NOT NULL DEFAULT 0, hours INTEGER NOT NULL DEFAULT 0,
wins INTEGER NOT NULL DEFAULT 0, wins INTEGER NOT NULL DEFAULT 0,
games INTEGER NOT NULL DEFAULT 0, games INTEGER NOT NULL DEFAULT 0,
avail_mode TEXT NOT NULL DEFAULT 'flex', avail_mode TEXT NOT NULL DEFAULT 'flex',
created_at TEXT NOT NULL DEFAULT (datetime('now')) availability_temp TEXT,
rejected_slots TEXT,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
); );
CREATE TABLE IF NOT EXISTS player_availability ( CREATE TABLE IF NOT EXISTS player_availability (
@@ -99,6 +101,12 @@ function migrateSchema() {
PRIMARY KEY (player_id, match_id) PRIMARY KEY (player_id, match_id)
); );
`); `);
// Idempotent column migrations
try { db.exec("ALTER TABLE matches ADD COLUMN proposed_teams TEXT"); } catch(e) {}
try { db.exec("ALTER TABLE matches ADD COLUMN players_arr TEXT DEFAULT '[]'"); } catch(e) {}
try { db.exec("ALTER TABLE players ADD COLUMN availability_temp TEXT"); } catch(e) {}
try { db.exec("ALTER TABLE players ADD COLUMN rejected_slots TEXT"); } catch(e) {}
} }
// ─── Players ─── // ─── Players ───
@@ -170,13 +178,13 @@ function updatePlayer(id, player) {
const merged = { ...existing, ...player }; const merged = { ...existing, ...player };
db.prepare(` db.prepare(`
UPDATE players SET name=?, level=?, position=?, telegram_id=?, pin=?, UPDATE players SET name=?, level=?, position=?, telegram_id=?, pin=?,
sessions=?, hours=?, wins=?, games=?, avail_mode=?, availability_temp=? sessions=?, hours=?, wins=?, games=?, avail_mode=?, availability_temp=?, rejected_slots=?
WHERE id=? WHERE id=?
`).run( `).run(
merged.name, merged.level, merged.position, merged.name, merged.level, merged.position,
String(merged.telegram_id || ''), String(merged.pin || ''), String(merged.telegram_id || ''), String(merged.pin || ''),
merged.sessions, merged.hours, merged.wins, merged.games, merged.sessions, merged.hours, merged.wins, merged.games,
merged.avail_mode, merged.availability_temp || null, id merged.avail_mode, merged.availability_temp || null, merged.rejected_slots || null, id
); );
if (player.availability !== undefined) { if (player.availability !== undefined) {
+1 -5
View File
@@ -11,7 +11,7 @@ const PORT = 3000;
// Load SQLite db layer (CommonJS module via createRequire) // Load SQLite db layer (CommonJS module via createRequire)
const require = createRequire(import.meta.url); const require = createRequire(import.meta.url);
const db = require("./db/db.cjs"); const db = require("./db.cjs");
app.use(express.json()); app.use(express.json());
app.use(express.static(path.join(__dirname, "..", "public"))); app.use(express.static(path.join(__dirname, "..", "public")));
@@ -561,10 +561,6 @@ app.listen(PORT, () => {
}); });
// Graceful shutdown
process.on("SIGTERM", () => { console.log("Shutting down..."); db.close(); process.exit(0); });
process.on("SIGINT", () => { console.log("Shutting down..."); db.close(); process.exit(0); });
// Graceful shutdown // Graceful shutdown
const closeSignal = (sig) => { const closeSignal = (sig) => {
console.log("Shutting down (" + sig + ")..."); console.log("Shutting down (" + sig + ")...");