Angehoerige lassen sich ohne Geburtsdatum erfassen; es wird nachgetragen, sobald es vorliegt. Die Spalte ist nicht mehr NOT NULL. Anlegen, Berichtigen und das vorgemerkte Anlegen im Nachtlauf wandeln ein leeres Feld in null statt in ein Datum, Berichtigen kann ein erfasstes Datum wieder leeren. Einstellungsassistent, Akte und Import verlangen das Feld nicht mehr. Geprueft: lint, tsc, types:check, 946 Tests, Waechter; alle Migrationen auf leerer Datenbank, zweiter Lauf ohne Befund; Rauchtest; Anlegen, Leeren und Nachtlauf ohne Geburtsdatum als alpenwerk_app.
91 lines
4.1 KiB
SQL
91 lines
4.1 KiB
SQL
-- Geburtsdatum der Angehörigen freiwillig
|
|
--
|
|
-- Fachlich vorgegeben: Angehörige dürfen 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, beim sofortigen
|
|
-- Anlegen ebenso wie im Nachtlauf, der ein vorgemerktes Anlegen ausführt.
|
|
--
|
|
-- Beim Berichtigen lässt sich ein erfasstes Geburtsdatum wieder leeren:
|
|
-- `case when ? then nullif` statt coalesce, dieselbe Form wie bei der
|
|
-- SV-Nummer daneben. Mit coalesce bliebe ein leeres Feld wirkungslos.
|
|
--
|
|
-- Geändert wird an der laufenden Definition, an genau einem Anker je
|
|
-- Ersetzung.
|
|
|
|
alter table employee_dependents alter column birth_date drop not null;
|
|
|
|
do $migration$
|
|
declare
|
|
v_ziele text[][] := array[
|
|
array['add_employee_dependent',
|
|
$a$nullif(payload->>'sv_nummer', ''), (payload->>'birth_date')::date$a$,
|
|
$a$nullif(payload->>'sv_nummer', ''), nullif(payload->>'birth_date', '')::date$a$],
|
|
array['update_employee_dependent',
|
|
$a$birth_date = coalesce((payload->>'birth_date')::date, birth_date),$a$,
|
|
$a$birth_date = case when payload ? 'birth_date' then nullif(payload->>'birth_date', '')::date else birth_date end,$a$],
|
|
array['update_employee_dependent',
|
|
$a$'Geburtsdatum', v_alt.birth_date::text, payload->>'birth_date'),$a$,
|
|
$a$'Geburtsdatum', v_alt.birth_date::text, nullif(payload->>'birth_date', '')),$a$],
|
|
array['apply_due_pending_changes',
|
|
$a$nullif(v_rec.payload->>'sv_nummer', ''), (v_rec.payload->>'birth_date')::date);$a$,
|
|
$a$nullif(v_rec.payload->>'sv_nummer', ''), nullif(v_rec.payload->>'birth_date', '')::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;
|
|
v_name text;
|
|
begin
|
|
if exists (select 1 from information_schema.columns
|
|
where table_schema = 'public' and table_name = 'employee_dependents'
|
|
and column_name = 'birth_date' and is_nullable = 'NO') then
|
|
raise exception 'employee_dependents.birth_date ist weiter NOT NULL.';
|
|
end if;
|
|
|
|
-- In keiner der drei Funktionen darf das Geburtsdatum noch ohne nullif
|
|
-- umgewandelt werden.
|
|
foreach v_name in array array['add_employee_dependent', 'update_employee_dependent', 'apply_due_pending_changes'] 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_name;
|
|
if position($a$payload->>'birth_date')::date$a$ in v_def) > 0 then
|
|
raise exception '%: das Geburtsdatum wird weiter ohne nullif umgewandelt.', v_name;
|
|
end if;
|
|
if v_name <> 'apply_due_pending_changes' and position('require_hr_admin()' in v_def) = 0 then
|
|
raise exception '%: require_hr_admin() fehlt.', v_name;
|
|
end if;
|
|
end 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 = 'update_employee_dependent';
|
|
if position($a$case when payload ? 'birth_date' then nullif(payload->>'birth_date', '')::date else birth_date end$a$ in v_def) = 0 then
|
|
raise exception 'update_employee_dependent lässt das Geburtsdatum nicht leeren.';
|
|
end if;
|
|
end
|
|
$pruefung$;
|