Alpenwerk HR — HR-Stammdatenverwaltung Mitarbeiter:innen, Organisationsstruktur, Planstellen, Eintritt, Austritt, Versetzung, Beförderung, Karenz, On- und Offboarding, Berichte, Exporte, Massenimport und ein lückenloser Nachweis jeder Änderung. Next.js 16, React 19 und TypeScript; PostgreSQL über Kysely; Anmeldung ausschliesslich über Microsoft Entra ID. Die Fachlogik liegt in der Datenbank, die Zugriffsschranke ist Row Level Security. Betrieb auf Windows Server: siehe deploy/windows/README.md. Sicherheitskonzept: docs/sicherheitskonzept.md.
62 lines
2.2 KiB
SQL
62 lines
2.2 KiB
SQL
-- Expliziter Cast auf employment_status in rehire_employee.
|
|
--
|
|
-- status = case when v_date <= current_date then 'Aktiv' else 'Geplant' end
|
|
--
|
|
-- Der case-Ausdruck ist `text`, die Spalte ist `employment_status`. Ohne
|
|
-- Cast weist Postgres das ab:
|
|
--
|
|
-- column "status" is of type employment_status but expression is of type text
|
|
--
|
|
-- Bei den beiden anderen Zuweisungen im selben update (exit_date, exit_reason)
|
|
-- stellt sich die Frage nicht: `null` ist typunabhängig.
|
|
|
|
do $$
|
|
declare
|
|
v_def text;
|
|
v_neu text;
|
|
begin
|
|
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.proname = 'rehire_employee'
|
|
limit 1;
|
|
|
|
v_neu := regexp_replace(
|
|
v_def,
|
|
'(case\s+when\s+v_date\s*<=\s*current_date\s+then\s+''Aktiv''\s+else\s+''Geplant''\s+end)',
|
|
'(\1)::employment_status',
|
|
'g'
|
|
);
|
|
|
|
if v_neu = v_def then
|
|
raise exception 'Das Muster für den Status passte nicht — rehire_employee blieb unverändert.';
|
|
end if;
|
|
|
|
execute v_neu;
|
|
end;
|
|
$$;
|
|
|
|
-- ═══ Gegenprobe ══════════════════════════════════════════════════
|
|
-- Nachgestellt wird die **Spaltenzuweisung**, nicht die an eine Variable.
|
|
-- Das ist der entscheidende Unterschied:
|
|
-- plpgsql wandelt bei einer Variablenzuweisung stillschweigend um, ein
|
|
-- UPDATE auf eine Spalte nicht. Nur die zweite Form entspricht dem Fehler.
|
|
do $$
|
|
begin
|
|
create temp table probe_status (s employment_status) on commit drop;
|
|
insert into probe_status values ('Aktiv');
|
|
|
|
begin
|
|
execute $probe$ update probe_status set s = (case when true then 'Aktiv' else 'Geplant' end)::text $probe$;
|
|
raise exception 'Eine text-Zuweisung an eine employment_status-Spalte wirft nicht mehr — die Prüfung ist wertlos geworden.';
|
|
exception
|
|
when datatype_mismatch then null; -- erwartet
|
|
end;
|
|
|
|
execute $probe$ update probe_status set s = (case when true then 'Aktiv' else 'Geplant' end)::employment_status $probe$;
|
|
if (select s from probe_status) <> 'Aktiv'::employment_status then
|
|
raise exception 'Die umgewandelte Form liefert nicht Aktiv.';
|
|
end if;
|
|
end;
|
|
$$;
|