v0.9.60 Ramsey recommended feature adds

This commit is contained in:
2026-03-17 18:43:25 -04:00
parent c823c86b63
commit b2b09cb0d0
6 changed files with 90 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "jama-backend",
"version": "0.9.59",
"version": "0.9.60",
"description": "TeamChat backend server",
"main": "src/index.js",
"scripts": {

View File

@@ -432,21 +432,19 @@ function initDb() {
// Migration: add columns if missing (must run before inserts)
try { db.exec("ALTER TABLE event_types ADD COLUMN is_protected INTEGER NOT NULL DEFAULT 0"); } catch(e) {}
try { db.exec("ALTER TABLE event_types ADD COLUMN default_duration_hrs REAL"); } catch(e) {}
// Delete the legacy "Default" type — "Event" is the canonical default
db.prepare("DELETE FROM event_types WHERE name = 'Default'").run();
// Seed built-in event types — "Event" is the primary default (1hr, protected, cannot edit/delete)
db.prepare("INSERT OR IGNORE INTO event_types (name, colour, is_default, is_protected, default_duration_hrs) VALUES ('Event', '#6366f1', 1, 1, 1.0)").run();
db.prepare("INSERT OR IGNORE INTO event_types (name, colour, default_duration_hrs) VALUES ('Game', '#22c55e', 3.0)").run();
db.prepare("INSERT OR IGNORE INTO event_types (name, colour, default_duration_hrs) VALUES ('Practice', '#f59e0b', 1.0)").run();
// Rename legacy "Default" to "Event" if it exists
db.prepare("UPDATE event_types SET name = 'Event', is_protected = 1, default_duration_hrs = 1.0 WHERE name = 'Default'").run();
// Remove the old separate "Event" type if it was created before this migration (was a duplicate)
// Keep whichever has is_default=1; delete duplicates
// Remove duplicates — keep the one with is_default=1
const evtTypes = db.prepare("SELECT id, is_default FROM event_types WHERE name = 'Event' ORDER BY is_default DESC").all();
if (evtTypes.length > 1) {
for (let i=1; i<evtTypes.length; i++) db.prepare('DELETE FROM event_types WHERE id = ?').run(evtTypes[i].id);
}
// Ensure built-in types are protected
db.prepare("UPDATE event_types SET is_protected = 1 WHERE name IN ('Event')").run();
// Ensure Game/Practice have correct durations
// Ensure built-in types are correct
db.prepare("UPDATE event_types SET is_protected = 1, is_default = 1, default_duration_hrs = 1.0 WHERE name = 'Event'").run();
db.prepare("UPDATE event_types SET default_duration_hrs = 3.0 WHERE name = 'Game'").run();
db.prepare("UPDATE event_types SET default_duration_hrs = 1.0 WHERE name = 'Practice'").run();
console.log('[DB] Schedule Manager tables ready');