90 day rolloff fix
Build and Push Docker Image / build (push) Successful in 16s

This commit is contained in:
2026-05-27 21:41:57 -05:00
parent 08401afd28
commit 6ce9788a6b
7 changed files with 249 additions and 116 deletions
+5 -11
View File
@@ -98,17 +98,11 @@ db.exec(`CREATE TABLE IF NOT EXISTS sessions (
expires_at DATETIME NOT NULL
)`);
// Recreate view so it always filters negated rows
db.exec(`DROP VIEW IF EXISTS active_cpas_scores;
CREATE VIEW active_cpas_scores AS
SELECT
employee_id,
SUM(points) AS active_points,
COUNT(*) AS violation_count
FROM violations
WHERE negated = 0
AND incident_date >= DATE('now', '-90 days')
GROUP BY employee_id;`);
// The old `active_cpas_scores` view implemented a naive per-violation 90-day
// window. CPAS standing now follows the clean-cycle roll-off model (see
// lib/rolloff.js), which is order-dependent and computed in JS, so the view is
// retired here to keep a single source of truth.
db.exec('DROP VIEW IF EXISTS active_cpas_scores;');
console.log('[DB] Connected:', dbPath);
module.exports = db;
+3 -10
View File
@@ -38,13 +38,6 @@ CREATE TABLE IF NOT EXISTS violation_resolutions (
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Active score: only non-negated violations in rolling 90 days
CREATE VIEW IF NOT EXISTS active_cpas_scores AS
SELECT
employee_id,
SUM(points) AS active_points,
COUNT(*) AS violation_count
FROM violations
WHERE negated = 0
AND incident_date >= DATE('now', '-90 days')
GROUP BY employee_id;
-- CPAS standing (active points + roll-off schedule) is computed in JS from the
-- clean-cycle model in lib/rolloff.js; see db/database.js for why the old
-- active_cpas_scores view was retired.