diff --git a/src/worker/base.rs b/src/worker/base.rs index 3f6a8f9..6475491 100644 --- a/src/worker/base.rs +++ b/src/worker/base.rs @@ -239,6 +239,19 @@ impl BaseWorker { // can show the change even if the DB-function doesn't write it. // We don't want to fail the whole operation if this insert fails, // so log errors and continue. + // Ensure money_history table exists (best-effort). If this fails, + // we still don't want to abort the money update. + 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 = uid_i32, diff --git a/src/worker/events.rs b/src/worker/events.rs index 2038703..e576e3e 100644 --- a/src/worker/events.rs +++ b/src/worker/events.rs @@ -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, diff --git a/src/worker/underground.rs b/src/worker/underground.rs index 2eada68..31df821 100644 --- a/src/worker/underground.rs +++ b/src/worker/underground.rs @@ -967,6 +967,17 @@ fn change_falukant_user_money( let money_str = format!("{:.2}", money_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 = falukant_user_id,