From 35377e3b599cb2a487c99e8386c6119e010552ed Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Sat, 6 Jun 2026 12:35:27 +0200 Subject: [PATCH] Wahlproblem gefixt --- docs/DEBUG_DEATH_SUCCESSION_QUERIES.sql | 8 ++++---- ..._falukant_log_political_office_history.sql | 9 ++++++++- src/worker/sql.rs | 20 +++++++++---------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/DEBUG_DEATH_SUCCESSION_QUERIES.sql b/docs/DEBUG_DEATH_SUCCESSION_QUERIES.sql index e55f2e7..acce28c 100644 --- a/docs/DEBUG_DEATH_SUCCESSION_QUERIES.sql +++ b/docs/DEBUG_DEATH_SUCCESSION_QUERIES.sql @@ -153,8 +153,8 @@ WITH removed AS ( ), archived_removed AS ( INSERT INTO falukant_log.political_office_history - (character_id, office_type_id, region_id, start_date, end_date) - SELECT character_id, office_type_id, region_id, created_at, NOW() + (character_id, office_type_id, region_id, start_date, end_date, created_at, updated_at) + SELECT character_id, office_type_id, region_id, created_at, NOW(), NOW(), NOW() FROM removed ), affected AS ( @@ -183,8 +183,8 @@ to_delete AS ( ), archived_trim AS ( INSERT INTO falukant_log.political_office_history - (character_id, office_type_id, region_id, start_date, end_date) - SELECT character_id, office_type_id, region_id, created_at, NOW() + (character_id, office_type_id, region_id, start_date, end_date, created_at, updated_at) + SELECT character_id, office_type_id, region_id, created_at, NOW(), NOW(), NOW() FROM to_delete ) DELETE FROM falukant_data.political_office diff --git a/migrations/016_falukant_log_political_office_history.sql b/migrations/016_falukant_log_political_office_history.sql index e9bada8..896672f 100644 --- a/migrations/016_falukant_log_political_office_history.sql +++ b/migrations/016_falukant_log_political_office_history.sql @@ -8,13 +8,20 @@ CREATE TABLE IF NOT EXISTS falukant_log.political_office_history ( region_id INTEGER, start_date TIMESTAMPTZ NOT NULL, end_date TIMESTAMPTZ NOT NULL, - created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() ); -- Tabelle kann bereits vom Backend existieren (ohne region_id o. Ä.): CREATE TABLE IF NOT EXISTS ergänzt keine Spalten. ALTER TABLE falukant_log.political_office_history ADD COLUMN IF NOT EXISTS region_id INTEGER; +ALTER TABLE falukant_log.political_office_history + ADD COLUMN IF NOT EXISTS created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(); + +ALTER TABLE falukant_log.political_office_history + ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(); + CREATE INDEX IF NOT EXISTS idx_pol_office_hist_character ON falukant_log.political_office_history (character_id); diff --git a/src/worker/sql.rs b/src/worker/sql.rs index 8cbedff..b48a212 100644 --- a/src/worker/sql.rs +++ b/src/worker/sql.rs @@ -1134,8 +1134,8 @@ pub const QUERY_SELECT_NEEDED_ELECTIONS: &str = r#" WHERE (po.created_at + (pot.term_length * INTERVAL '1 day'))::date = td.election_date ), archived_expiring AS ( - INSERT INTO falukant_log.political_office_history (character_id, office_type_id, region_id, start_date, end_date) - SELECT character_id, office_type_id, region_id, start_date, end_date + INSERT INTO falukant_log.political_office_history (character_id, office_type_id, region_id, start_date, end_date, created_at, updated_at) + SELECT character_id, office_type_id, region_id, start_date, end_date, NOW(), NOW() FROM offices_ending_today ), expired_today AS ( @@ -1265,8 +1265,8 @@ pub const QUERY_PROCESS_EXPIRED_AND_SCHEDULE: &str = r#" WHERE (po.created_at + (pot.term_length * INTERVAL '1 day')) <= NOW() ), archived_expired AS ( - INSERT INTO falukant_log.political_office_history (character_id, office_type_id, region_id, start_date, end_date) - SELECT character_id, office_type_id, region_id, start_date, term_end + INSERT INTO falukant_log.political_office_history (character_id, office_type_id, region_id, start_date, end_date, created_at, updated_at) + SELECT character_id, office_type_id, region_id, start_date, term_end, NOW(), NOW() FROM doomed ), expired_offices AS ( @@ -1653,8 +1653,8 @@ pub const QUERY_TRIM_EXCESS_OFFICES_GLOBAL: &str = r#" WHERE rn > seats_total ), archived_trim AS ( - INSERT INTO falukant_log.political_office_history (character_id, office_type_id, region_id, start_date, end_date) - SELECT character_id, office_type_id, region_id, created_at, NOW() + INSERT INTO falukant_log.political_office_history (character_id, office_type_id, region_id, start_date, end_date, created_at, updated_at) + SELECT character_id, office_type_id, region_id, created_at, NOW(), NOW(), NOW() FROM to_delete ) DELETE FROM falukant_data.political_office @@ -2532,8 +2532,8 @@ pub const QUERY_DELETE_POLITICAL_OFFICE: &str = r#" RETURNING character_id, office_type_id, region_id, created_at ), archived_removed AS ( - INSERT INTO falukant_log.political_office_history (character_id, office_type_id, region_id, start_date, end_date) - SELECT character_id, office_type_id, region_id, created_at, NOW() + INSERT INTO falukant_log.political_office_history (character_id, office_type_id, region_id, start_date, end_date, created_at, updated_at) + SELECT character_id, office_type_id, region_id, created_at, NOW(), NOW(), NOW() FROM removed ), affected AS ( @@ -2575,8 +2575,8 @@ pub const QUERY_DELETE_POLITICAL_OFFICE: &str = r#" WHERE rn > seats_total ), archived_trim AS ( - INSERT INTO falukant_log.political_office_history (character_id, office_type_id, region_id, start_date, end_date) - SELECT character_id, office_type_id, region_id, created_at, NOW() + INSERT INTO falukant_log.political_office_history (character_id, office_type_id, region_id, start_date, end_date, created_at, updated_at) + SELECT character_id, office_type_id, region_id, created_at, NOW(), NOW(), NOW() FROM to_delete ) DELETE FROM falukant_data.political_office