Enhance money history tracking: Implement best-effort creation of money_history table in BaseWorker, EventsWorker, and UndergroundWorker to ensure logging of monetary changes without operation failure.

This commit is contained in:
Torsten Schulz (local)
2025-12-09 08:53:39 +01:00
parent d740dbbf73
commit c801e50def
3 changed files with 35 additions and 0 deletions

View File

@@ -1013,6 +1013,17 @@ impl EventsWorker {
let money_str = format!("{:.2}", change);
fn escape_sql_literal(s: &str) -> String { s.replace('\'', "''") }
let escaped_action = escape_sql_literal(&action);
let create_sql = r#"
CREATE TABLE IF NOT EXISTS falukant_log.money_history (
id BIGSERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
change NUMERIC(10,2) NOT NULL,
action TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
"#;
let _ = conn.query(create_sql);
let history_sql = format!(
"INSERT INTO falukant_log.money_history (user_id, change, action, created_at) VALUES ({uid}, {money}::numeric, '{act}', NOW());",
uid = user_id,