p4 #9
@@ -18,6 +18,21 @@ const cols = db.prepare("PRAGMA table_info(violations)").all().map(c => c.name);
|
||||
if (!cols.includes('negated')) db.exec("ALTER TABLE violations ADD COLUMN negated INTEGER NOT NULL DEFAULT 0");
|
||||
if (!cols.includes('negated_at')) db.exec("ALTER TABLE violations ADD COLUMN negated_at DATETIME");
|
||||
|
||||
// After adding columns + resolutions table, ensure view is correct
|
||||
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;
|
||||
`);
|
||||
|
||||
|
||||
// Ensure resolutions table exists on upgrade
|
||||
db.exec(`CREATE TABLE IF NOT EXISTS violation_resolutions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
||||
Reference in New Issue
Block a user