Remove Supabase
Some checks failed
CI / Lint, Typen, Tests, Build (push) Failing after 5m40s
CI / Migrationen auf leerer Datenbank (push) Has been cancelled

The database moved to a container of our own; the platform is gone.
This takes out what was left of it — and, where the leftovers were load
bearing, moves rather than deletes.

Moved, not deleted:

  supabase/migrations/  -> db/migrations/      the schema's source of truth
  supabase/build-org.ts -> scripts/build-org.ts
  lib/supabase/types.ts -> lib/types.ts        52 import sites repointed

The bookkeeping needed care. It lived in `supabase_migrations.schema_migrations`,
and simply renaming the schema would have left the runner facing an empty
table: it would have called all 67 migrations pending and replayed them
against a database that is long since current. So the runner now creates
`migrationen.schema_migrations` and, once, copies the old rows across —
guarded so a second run does nothing and a fresh database skips it entirely.
Only then does migration 20260907100000 drop the old schema.

Deleted: the CLI config, the seed, the historical schema/function dumps
(nothing read them), scripts/umzug-von-supabase.sh (the move is done), and
both Supabase packages plus the CLI. Nothing in the application imported
them — the build now succeeds with no environment variables at all, which
is the proof.

Integration tests: six of them signed in through Supabase Auth and asserted
against the anon key and the service role. That model is gone, so the tests
were not portable — they are deleted. session-context and
employee-status-filter already ran on pg and are untouched; om-reporting is
ported to a direct connection because it guards a real risk (the reporting
line rule exists twice, once in SQL and once in TypeScript).

CI: the integration job started a Supabase stack. It now runs a postgres
service, applies deploy/db-init and every migration to an empty database —
that was the valuable part, and it still holds — then checks that a second
run is a no-op, which is what proves the bookkeeping works.

Docs: security-review.md audited a service-role key, a cookie adapter and
auth.users, none of which exist. Restating findings about removed components
would suggest today's system had been reviewed; it has not. It now records
what was removed and says a fresh review is due. data-model.md was already
marked obsolete and described the pre-OM schema; azure-migration.md was a
plan for a route not taken. Both deleted.

Verified: npm ci, typecheck, lint, 445 tests, build — all clean without the
packages. Integration tests skip cleanly with no database. Migration SQL and
the runner are reviewed but NOT executed: no Docker here, and the old
instance no longer resolves.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-07 10:43:22 +02:00
parent 5c310c3a58
commit b87c8ad64c
155 changed files with 386 additions and 4014 deletions

View File

@@ -0,0 +1,120 @@
-- Die Personalnummer wird eingegeben, nicht vergeben.
--
-- Sie muss mit Loga und Interflex übereinstimmen. Eine von dieser Anwendung
-- selbst gezogene Nummer ist dort unbekannt, und die Person hätte in drei
-- Systemen zwei Nummern.
--
-- Zwei Dinge ändern sich dadurch:
--
-- 1. Die Identität fällt weg. `GENERATED ALWAYS` weist eigene Werte
-- ausdrücklich ab — deshalb brauchte der Import bisher OVERRIDING SYSTEM
-- VALUE.
-- 2. Die Eindeutigkeit muss ausdrücklich her. Bisher gab es **keine**: die
-- Identität verhinderte Doppelte nur als Nebenwirkung. Sobald der Wert von
-- aussen kommt, ist das die eigentliche Zusicherung — und sie fehlte.
-- Gegenprobe vor dem Umbau: was jetzt doppelt ist, liesse sich danach nicht
-- mehr eindeutig machen.
do $$
declare v_doppelt int;
begin
select count(*) into v_doppelt from (
select personnel_number from employees group by 1 having count(*) > 1
) x;
if v_doppelt > 0 then
raise exception '% Personalnummern kommen mehrfach vor — vor der Umstellung bereinigen.', v_doppelt;
end if;
end;
$$;
alter table employees alter column personnel_number drop identity if exists;
alter table employees add constraint employees_personnel_number_key unique (personnel_number);
comment on column employees.personnel_number is
'Wird eingegeben und muss mit Loga/Interflex übereinstimmen. Nicht automatisch vergeben.';
-- ═══ hire_employee nimmt die Nummer entgegen ═════════════════════
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 = 'hire_employee' limit 1;
-- Pflichtprüfung direkt nach der Planstellenprüfung einhängen.
v_neu := regexp_replace(
v_def,
'(if\s+v_position_id\s+is\s+null\s+then\s+raise\s+exception\s+''Es muss eine Planstelle angegeben werden\.'';\s+end\s+if;)',
$neu$\1
if payload->>'personnel_number' is null or btrim(payload->>'personnel_number') = '' then
raise exception 'Es muss eine Personalnummer angegeben werden.';
end if;
if exists (select 1 from employees where personnel_number = (payload->>'personnel_number')::int) then
raise exception 'Die Personalnummer % ist bereits vergeben.', payload->>'personnel_number';
end if;$neu$,
'g'
);
if v_neu = v_def then
raise exception 'Die Pflichtprüfung liess sich nicht einhängen — hire_employee blieb unverändert.';
end if;
v_def := v_neu;
-- Und in die Einfügung aufnehmen. Die Spaltenliste beginnt mit
-- first_name; davor kommt personnel_number, in beiden Listen an gleicher
-- Stelle.
v_neu := regexp_replace(v_def, 'insert\s+into\s+employees\s*\(\s*first_name,', 'insert into employees (' || chr(10) || ' personnel_number, first_name,', 'g');
if v_neu = v_def then
raise exception 'Die Spaltenliste liess sich nicht ergänzen.';
end if;
v_def := v_neu;
v_neu := regexp_replace(v_def, 'values\s*\(\s*payload->>''first_name'',', 'values (' || chr(10) || ' (payload->>''personnel_number'')::int, payload->>''first_name'',', 'g');
if v_neu = v_def then
raise exception 'Die Werteliste liess sich nicht ergänzen.';
end if;
-- OVERRIDING SYSTEM VALUE gibt es nur für Identitätsspalten; nach dem
-- Wegfall wäre es ein Fehler. Der Import setzt es selbst nicht mehr, hier
-- steht es vorsorglich, falls eine ältere Fassung es doch trägt.
v_neu := regexp_replace(v_neu, '\s+overriding\s+system\s+value', '', 'gi');
execute v_neu;
end;
$$;
-- ═══ Gegenprobe ══════════════════════════════════════════════════
do $$
declare
v_ist_identitaet text;
v_def text;
begin
select is_identity into v_ist_identitaet
from information_schema.columns
where table_name = 'employees' and column_name = 'personnel_number';
if v_ist_identitaet <> 'NO' then
raise exception 'personnel_number ist weiterhin eine Identitätsspalte.';
end if;
if not exists (
select 1 from pg_constraint
where conrelid = 'employees'::regclass and contype = 'u'
and pg_get_constraintdef(oid) = 'UNIQUE (personnel_number)'
) then
raise exception 'Die Eindeutigkeit auf personnel_number fehlt.';
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.proname = 'hire_employee' limit 1;
if v_def not like '%bereits vergeben%' then
raise exception 'hire_employee() prüft die Personalnummer nicht.';
end if;
if v_def ilike '%overriding system value%' then
raise exception 'hire_employee() enthält weiterhin OVERRIDING SYSTEM VALUE.';
end if;
end;
$$;