- Migrationskoepfe Staatsbuergerschaft und Arbeitszeitmodell beschreiben den heutigen Stand statt einer Fehlerliste (nur Kommentare ausserhalb $$) - Testnamen ohne "nicht mehr"/"wie bisher", Beispieladressen @firma.example - Override minimatch ^11.0.1 fuer @typescript-eslint/typescript-estree (npm audit: 0 Schwachstellen)
93 lines
4.1 KiB
SQL
93 lines
4.1 KiB
SQL
-- Staatsbürgerschaft ohne Vorgabe.
|
|
--
|
|
-- Eine Vorgabe stünde in der Akte, in den Exporten und in den Berichten wie
|
|
-- eine erhobene Angabe — auch bei externen Personen, deren Einstellung die
|
|
-- Staatsbürgerschaft gar nicht fragt.
|
|
--
|
|
-- Die Spalte ist deshalb freiwillig; leer heisst „nicht erfasst". Die Funktionen,
|
|
-- die sie schreiben, nehmen die leere Zeichenkette als null — dieselbe Form
|
|
-- wie bei den übrigen freiwilligen Feldern (case when ? then nullif). Ein
|
|
-- nicht geschickter Schlüssel lässt den gespeicherten Wert stehen.
|
|
--
|
|
-- Bestehende Zeilen bleiben, wie sie sind: ob dort „Österreich" erhoben
|
|
-- oder vorgegeben war, lässt sich nicht mehr unterscheiden. Bei externen
|
|
-- Personen zeigt die Akte die Vorgabe weiterhin als leer
|
|
-- (lib/extern-vorgaben.ts).
|
|
|
|
alter table employees alter column nationality drop not null;
|
|
alter table employees alter column nationality drop default;
|
|
|
|
do $migration$
|
|
declare
|
|
v_def text;
|
|
v_treffer int;
|
|
v_alt text;
|
|
v_neu text;
|
|
v_fn text;
|
|
v_paar text[];
|
|
v_paare text[][] := array[
|
|
array['change_employee_data',
|
|
E' nationality = coalesce(v_person->>''nationality'', nationality),\n',
|
|
E' nationality = case when v_person ? ''nationality'' then nullif(v_person->>''nationality'', '''') else nationality end,\n'],
|
|
array['rehire_employee',
|
|
E' nationality = coalesce(payload->>''nationality'', nationality),\n',
|
|
E' nationality = case when payload ? ''nationality'' then nullif(payload->>''nationality'', '''') else nationality end,\n'],
|
|
array['hire_employee',
|
|
E' coalesce(payload->>''nationality'', ''Österreich''), ',
|
|
E' nullif(payload->>''nationality'', ''''), '],
|
|
array['apply_due_pending_changes',
|
|
E' nationality = coalesce(v_rec.payload->''person''->>''nationality'', nationality),\n',
|
|
E' nationality = case when v_rec.payload->''person'' ? ''nationality'' then nullif(v_rec.payload->''person''->>''nationality'', '''') else nationality end,\n']
|
|
];
|
|
begin
|
|
foreach v_paar slice 1 in array v_paare loop
|
|
v_fn := v_paar[1];
|
|
v_alt := v_paar[2];
|
|
v_neu := v_paar[3];
|
|
if v_fn = 'apply_due_pending_changes' then
|
|
v_def := pg_get_functiondef('public.apply_due_pending_changes()'::regprocedure);
|
|
else
|
|
v_def := pg_get_functiondef(format('public.%I(jsonb)', v_fn)::regprocedure);
|
|
end if;
|
|
if position(v_neu in v_def) > 0 then
|
|
raise notice '% schreibt die Staatsbürgerschaft bereits freiwillig — nichts zu tun.', v_fn;
|
|
continue;
|
|
end if;
|
|
v_treffer := (length(v_def) - length(replace(v_def, v_alt, ''))) / length(v_alt);
|
|
if v_treffer <> 1 then
|
|
raise exception 'Der Anker in % kommt % mal vor, erwartet genau einmal.', v_fn, v_treffer;
|
|
end if;
|
|
execute replace(v_def, v_alt, v_neu);
|
|
end loop;
|
|
end
|
|
$migration$;
|
|
|
|
do $pruefung$
|
|
declare
|
|
v_fn text;
|
|
v_def text;
|
|
begin
|
|
if (select is_nullable from information_schema.columns
|
|
where table_schema = 'public' and table_name = 'employees' and column_name = 'nationality') <> 'YES' then
|
|
raise exception 'employees.nationality ist weiterhin Pflicht.';
|
|
end if;
|
|
if (select column_default from information_schema.columns
|
|
where table_schema = 'public' and table_name = 'employees' and column_name = 'nationality') is not null then
|
|
raise exception 'employees.nationality hat weiterhin eine Vorgabe.';
|
|
end if;
|
|
foreach v_fn in array array['change_employee_data(jsonb)', 'rehire_employee(jsonb)', 'hire_employee(jsonb)', 'apply_due_pending_changes()'] loop
|
|
v_def := pg_get_functiondef(('public.' || v_fn)::regprocedure);
|
|
if v_def ~ 'coalesce\([^\n]*nationality' then
|
|
raise exception '% setzt die Staatsbürgerschaft weiterhin mit coalesce.', v_fn;
|
|
end if;
|
|
if v_def !~ 'nullif\([^\n]*nationality' then
|
|
raise exception '% macht aus einer leeren Staatsbürgerschaft kein null.', v_fn;
|
|
end if;
|
|
-- Was dabei nicht verloren gehen darf.
|
|
if v_fn <> 'apply_due_pending_changes()' and position('perform require_hr_admin();' in v_def) = 0 then
|
|
raise exception 'require_hr_admin() fehlt in %.', v_fn;
|
|
end if;
|
|
end loop;
|
|
end
|
|
$pruefung$;
|