-- Geburtsdatum bei der Einstellung freiwillig -- -- Fachlich vorgegeben: eine Einstellung darf ohne Geburtsdatum erfasst -- werden; es wird nachgetragen, sobald es vorliegt. Die Spalte ist damit -- nicht mehr NOT NULL. Ein leer geschicktes Feld wird null und nicht in ein -- Datum umgewandelt — sonst bräche die Umwandlung von '' ab. -- -- Geändert wird an der laufenden Definition, an genau einem Anker je -- Funktion. alter table employees alter column birth_date drop not null; do $migration$ declare v_ziele text[][] := array[ array['hire_employee', $a$(payload->>'birth_date')::date, payload->>'sv_nummer',$a$, $a$nullif(payload->>'birth_date', '')::date, payload->>'sv_nummer',$a$], array['rehire_employee', $a$birth_date = coalesce((payload->>'birth_date')::date, birth_date),$a$, $a$birth_date = coalesce(nullif(payload->>'birth_date', '')::date, birth_date),$a$], array['change_employee_data', $a$birth_date = coalesce((v_person->>'birth_date')::date, birth_date),$a$, $a$birth_date = coalesce(nullif(v_person->>'birth_date', '')::date, birth_date),$a$], array['apply_due_pending_changes', $a$birth_date = coalesce((v_rec.payload->'person'->>'birth_date')::date, birth_date),$a$, $a$birth_date = coalesce(nullif(v_rec.payload->'person'->>'birth_date', '')::date, birth_date),$a$] ]; v_def text; v_treffer integer; i integer; begin for i in 1 .. array_length(v_ziele, 1) loop select pg_get_functiondef(p.oid) into v_def from pg_proc p join pg_namespace n on n.oid = p.pronamespace where n.nspname = 'public' and p.prokind = 'f' and p.proname = v_ziele[i][1]; if v_def is null then raise exception '% ist nicht vorhanden.', v_ziele[i][1]; end if; if position(v_ziele[i][3] in v_def) > 0 then raise notice '% ist bereits angepasst — nichts zu tun.', v_ziele[i][1]; continue; end if; v_treffer := (length(v_def) - length(replace(v_def, v_ziele[i][2], ''))) / length(v_ziele[i][2]); if v_treffer <> 1 then raise exception '%: der Anker kommt % mal vor, erwartet genau einmal.', v_ziele[i][1], v_treffer; end if; execute replace(v_def, v_ziele[i][2], v_ziele[i][3]); end loop; end $migration$; do $pruefung$ declare v_def text; begin if exists (select 1 from information_schema.columns where table_schema = 'public' and table_name = 'employees' and column_name = 'birth_date' and is_nullable = 'NO') then raise exception 'employees.birth_date ist weiter NOT NULL.'; end if; select pg_get_functiondef(p.oid) into v_def from pg_proc p join pg_namespace n on n.oid = p.pronamespace where n.nspname = 'public' and p.prokind = 'f' and p.proname = 'hire_employee'; if position($a$nullif(payload->>'birth_date', '')::date$a$ in v_def) = 0 or position('require_hr_admin()' in v_def) = 0 or position('lehrzeit_von' in v_def) = 0 then raise exception 'hire_employee ist nicht wie erwartet angepasst.'; end if; end $pruefung$;