This commit is contained in:
+5
-11
@@ -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
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user