Files
yourpart-daemon/migrations/016_falukant_log_political_office_history.sql

29 lines
1.3 KiB
SQL

-- Abgeschlossene politische Ämter (Amtsende, Neubesetzung, Entfernung) für Auswertung „Karrierehöchstwert“ / UI.
-- Wird vom YpDaemon vor Löschen aus falukant_data.political_office befüllt.
CREATE TABLE IF NOT EXISTS falukant_log.political_office_history (
id BIGSERIAL PRIMARY KEY,
character_id INTEGER NOT NULL,
office_type_id INTEGER NOT NULL,
region_id INTEGER,
start_date TIMESTAMPTZ NOT NULL,
end_date TIMESTAMPTZ NOT NULL,
created_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;
CREATE INDEX IF NOT EXISTS idx_pol_office_hist_character
ON falukant_log.political_office_history (character_id);
CREATE INDEX IF NOT EXISTS idx_pol_office_hist_office_type
ON falukant_log.political_office_history (office_type_id);
CREATE INDEX IF NOT EXISTS idx_pol_office_hist_region
ON falukant_log.political_office_history (region_id);
COMMENT ON TABLE falukant_log.political_office_history IS
'Politische Amtszeiten nach Ende; start_date/end_date aus Amtszeile bzw. NOW() bei vorzeitigem Ende (YpDaemon).';