rework vehicle handling

This commit is contained in:
Matthias Hochmeister
2026-02-28 13:57:41 +01:00
parent 41fc41bee4
commit 1e478479be
12 changed files with 85 additions and 26 deletions

View File

@@ -0,0 +1,24 @@
-- Migration 010: Simplify WartungslogArt from 7 types to 3
-- Maps existing data to new categories and updates the CHECK constraint.
--
-- Old types: New type:
-- Inspektion -> Service
-- Reparatur -> Service
-- Reifenwechsel -> Service
-- Reinigung -> Service
-- Hauptuntersuchung -> §57a Prüfung
-- Kraftstoff -> Sonstiges
-- Sonstiges -> Sonstiges (unchanged)
-- Step 1: Migrate existing data to new type values
UPDATE fahrzeug_wartungslog SET art = 'Service' WHERE art IN ('Inspektion', 'Reparatur', 'Reifenwechsel', 'Reinigung');
UPDATE fahrzeug_wartungslog SET art = '§57a Prüfung' WHERE art = 'Hauptuntersuchung';
UPDATE fahrzeug_wartungslog SET art = 'Sonstiges' WHERE art = 'Kraftstoff';
-- Step 2: Drop the old CHECK constraint on art
ALTER TABLE fahrzeug_wartungslog DROP CONSTRAINT IF EXISTS fahrzeug_wartungslog_art_check;
-- Step 3: Add the new CHECK constraint with simplified types
ALTER TABLE fahrzeug_wartungslog
ADD CONSTRAINT fahrzeug_wartungslog_art_check
CHECK (art IS NULL OR art IN ('§57a Prüfung', 'Service', 'Sonstiges'));