Files
yourpart3/backend/sql/falukant_political_office_benefits.sql
Torsten Schulz (local) 5fcd55be43
All checks were successful
Deploy to production / deploy (push) Successful in 2m52s
feat(vocab): add dashboard learning summary and related endpoints
- Introduced `getDashboardLearningSummary` method in `VocabService` to provide a compact overview of enrolled courses and current lessons for users.
- Updated `vocabController` to include a new route for the dashboard widget, allowing users to access their learning summary.
- Enhanced `vocabRouter` to route requests for the new dashboard widget endpoint.
- Added localization support for the new dashboard features across multiple languages, improving user engagement and accessibility.
- Updated UI components to integrate the new dashboard widget, ensuring a seamless user experience.
2026-04-02 15:06:50 +02:00

164 lines
7.4 KiB
SQL

-- =============================================================================
-- Politische Amtsvorteile (falukant_predefine.political_office_benefit)
-- =============================================================================
--
-- Fehler „SQL Error [08003]: This connection has been closed“
-- -----------------------------------------------------------
-- Das ist meist KEIN Inhaltfehler dieses Skripts, sondern:
-- 1) Eine VORHERIGE Anweisung in derselben Session ist fehlgeschlagen → die
-- Transaktion ist abgebrochen; der Client meldet dann oft nur noch 08003.
-- → Neue Verbindung öffnen, ggf. ROLLBACK; dann erneut ausführen.
-- 2) Fehler 23502: political_office_id NOT NULL, aber INSERT nutzt nur office_type_id
-- (beide Spalten nach Sync) → dieses Skript gleicht das Schema zuerst an.
-- 3) Spalte office_type_id fehlt komplett → Migration 20260401120000 ausführen.
-- 4) PgBouncer (Pool) im Transaction-Modus: lange Skripte mit vielen
-- Statements trennen die Verbindung → einzelne Blöcke nacheinander
-- ausführen oder Datei falukant_political_office_benefits_steps.sql nutzen.
-- 5) Netzwerk / Server-Neustart / Idle-Timeout.
--
-- Empfehlung: Im Terminal mit psql und ON_ERROR_STOP (bricht beim ersten Fehler
-- sauber ab und zeigt die echte Meldung):
-- psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f backend/sql/falukant_political_office_benefits.sql
--
-- JSON value daily_salary:
-- • dailyAmount: fester Tagesbetrag (überschreibt base/perRank)
-- • base + perRank: Auszahlung = base + (Amtsrang * perRank)
-- JSON value tax_exemption:
-- • regions: Text-Array (z. B. "city") oder "*" für alle Ebenen
-- =============================================================================
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'falukant_predefine' AND table_name = 'political_office_benefit'
) THEN
RAISE EXCEPTION 'Tabelle falukant_predefine.political_office_benefit fehlt.';
END IF;
-- Legacy: nur political_office_id (speichert fälschlich die office_type_id)
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'falukant_predefine'
AND table_name = 'political_office_benefit'
AND column_name = 'political_office_id'
) AND NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'falukant_predefine'
AND table_name = 'political_office_benefit'
AND column_name = 'office_type_id'
) THEN
ALTER TABLE falukant_predefine.political_office_benefit
RENAME COLUMN political_office_id TO office_type_id;
END IF;
-- Doppel-Spalten nach Sequelize: office_type_id wird befüllt, political_office_id bleibt NULL → 23502
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'falukant_predefine'
AND table_name = 'political_office_benefit'
AND column_name = 'political_office_id'
) AND EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'falukant_predefine'
AND table_name = 'political_office_benefit'
AND column_name = 'office_type_id'
) THEN
UPDATE falukant_predefine.political_office_benefit
SET office_type_id = COALESCE(office_type_id, political_office_id);
ALTER TABLE falukant_predefine.political_office_benefit
DROP COLUMN political_office_id;
END IF;
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'falukant_predefine'
AND table_name = 'political_office_benefit'
AND column_name = 'office_type_id'
) THEN
RAISE EXCEPTION
'Spalte office_type_id fehlt. Migration 20260401120000-politics-benefits-and-daily-salary.cjs ausführen.';
END IF;
END $$;
-- Benefit-Typen (falls noch nicht aus App-Init vorhanden)
INSERT INTO falukant_type.political_office_benefit_type (tr)
SELECT 'tax_exemption'
WHERE NOT EXISTS (
SELECT 1 FROM falukant_type.political_office_benefit_type t WHERE t.tr = 'tax_exemption'
);
INSERT INTO falukant_type.political_office_benefit_type (tr)
SELECT 'daily_salary'
WHERE NOT EXISTS (
SELECT 1 FROM falukant_type.political_office_benefit_type t WHERE t.tr = 'daily_salary'
);
-- Steuerbefreiungen (wie POLITICAL_TAX_EXEMPTIONS im Backend)
INSERT INTO falukant_predefine.political_office_benefit (office_type_id, benefit_type_id, value)
SELECT ot.id, bt.id, '{"regions":["city"]}'::jsonb
FROM falukant_type.political_office_type ot
JOIN falukant_type.political_office_benefit_type bt ON bt.tr = 'tax_exemption'
WHERE ot.name = 'council'
AND NOT EXISTS (
SELECT 1 FROM falukant_predefine.political_office_benefit x
WHERE x.office_type_id = ot.id AND x.benefit_type_id = bt.id
);
INSERT INTO falukant_predefine.political_office_benefit (office_type_id, benefit_type_id, value)
SELECT ot.id, bt.id, '{"regions":["city","county"]}'::jsonb
FROM falukant_type.political_office_type ot
JOIN falukant_type.political_office_benefit_type bt ON bt.tr = 'tax_exemption'
WHERE ot.name = 'taxman'
AND NOT EXISTS (
SELECT 1 FROM falukant_predefine.political_office_benefit x
WHERE x.office_type_id = ot.id AND x.benefit_type_id = bt.id
);
INSERT INTO falukant_predefine.political_office_benefit (office_type_id, benefit_type_id, value)
SELECT ot.id, bt.id, '{"regions":["city","county","shire"]}'::jsonb
FROM falukant_type.political_office_type ot
JOIN falukant_type.political_office_benefit_type bt ON bt.tr = 'tax_exemption'
WHERE ot.name = 'treasurer'
AND NOT EXISTS (
SELECT 1 FROM falukant_predefine.political_office_benefit x
WHERE x.office_type_id = ot.id AND x.benefit_type_id = bt.id
);
INSERT INTO falukant_predefine.political_office_benefit (office_type_id, benefit_type_id, value)
SELECT ot.id, bt.id, '{"regions":["city","county","shire","markgrave","duchy"]}'::jsonb
FROM falukant_type.political_office_type ot
JOIN falukant_type.political_office_benefit_type bt ON bt.tr = 'tax_exemption'
WHERE ot.name = 'super-state-administrator'
AND NOT EXISTS (
SELECT 1 FROM falukant_predefine.political_office_benefit x
WHERE x.office_type_id = ot.id AND x.benefit_type_id = bt.id
);
INSERT INTO falukant_predefine.political_office_benefit (office_type_id, benefit_type_id, value)
SELECT ot.id, bt.id, '{"regions":["*"]}'::jsonb
FROM falukant_type.political_office_type ot
JOIN falukant_type.political_office_benefit_type bt ON bt.tr = 'tax_exemption'
WHERE ot.name = 'chancellor'
AND NOT EXISTS (
SELECT 1 FROM falukant_predefine.political_office_benefit x
WHERE x.office_type_id = ot.id AND x.benefit_type_id = bt.id
);
-- Tageslohn: base + Amtsrang * perRank (Rang in App: POLITICAL_OFFICE_RANKS)
INSERT INTO falukant_predefine.political_office_benefit (office_type_id, benefit_type_id, value)
SELECT ot.id, bt.id, '{"base":4,"perRank":11}'::jsonb
FROM falukant_type.political_office_type ot
JOIN falukant_type.political_office_benefit_type bt ON bt.tr = 'daily_salary'
WHERE ot.name IN (
'assessor', 'councillor', 'council', 'beadle', 'town-clerk', 'mayor',
'master-builder', 'village-major', 'judge', 'bailif', 'taxman', 'sheriff',
'consultant', 'treasurer', 'hangman', 'territorial-council',
'territorial-council-speaker', 'ruler-consultant', 'state-administrator',
'super-state-administrator', 'governor', 'ministry-helper', 'minister', 'chancellor'
)
AND NOT EXISTS (
SELECT 1 FROM falukant_predefine.political_office_benefit x
WHERE x.office_type_id = ot.id AND x.benefit_type_id = bt.id
);