25 lines
1.2 KiB
SQL
25 lines
1.2 KiB
SQL
-- 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: Drop the old CHECK constraint FIRST (must happen before data changes)
|
|
ALTER TABLE fahrzeug_wartungslog DROP CONSTRAINT IF EXISTS fahrzeug_wartungslog_art_check;
|
|
|
|
-- Step 2: 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 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'));
|