Load a whole organisation from a file, or none of it
Second half of the mass import: the transactional loader, the /import page
and a template generated from the same schema the validation uses.
Everything happens in one transaction. A half-loaded organisation — areas
without departments, positions without people — is worse than none, because
it looks like data. The dry run is the same code path with a rollback at the
end, so the report is built against the real current state rather than a
copy, and nothing is cached between checking and committing: the file is
sent twice. That costs one upload and avoids server-side state that can
expire, fill up, or be confused between two people.
Personnel numbers are taken from the file, not reassigned. personnel_number
is GENERATED ALWAYS AS IDENTITY, so this needs OVERRIDING SYSTEM VALUE and a
hand-written insert — worth it, because the number is on payslips, in files
and on badges. An import that reissues it is not a migration. The identity
counter is advanced afterwards; without that the next hire draws a number
the import already used, and the unique index refuses it weeks later, far
from the cause.
Three defects the first real run against the database exposed, none of which
typecheck, lint or 231 tests could have found:
- weekly_hours is bound to employment type by a CHECK constraint: full time
is exactly 38.5. The import reached the insert and was rolled back. Now
it is a finding with a row number.
- Titles are restricted to a fixed list by another CHECK. Same treatment.
- setval() needs UPDATE on the sequence, which `usage, select` does not
grant. Migration 20260803120000 adds it; until it is applied, an import
containing people will fail at the last step and take itself back.
I also had exit_date > entry_date where the database has >=. Someone who
never starts enters and leaves the same day; the stricter rule would have
rejected a real case.
Verified against the live database through the actual route and session: a
file with four deliberate faults produced exactly four findings, each with
sheet, row and column, and the rollback left nothing behind.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -157,7 +157,55 @@ describe("Personen", () => {
|
||||
[blatt("Personen", spalten, [[...person("1", "a@example.at", "60000001"), "01.01.2010", "Kündigung"]])],
|
||||
BESTAND
|
||||
);
|
||||
expect(meldungen(zuFrueh.fehler).join(" ")).toContain("Liegt nicht nach dem Eintritt");
|
||||
expect(meldungen(zuFrueh.fehler).join(" ")).toContain("Liegt vor dem Eintritt");
|
||||
});
|
||||
|
||||
it("lässt Ein- und Austritt am selben Tag zu", () => {
|
||||
// Wer den Dienst nicht antritt, tritt am selben Tag ein und aus. Die
|
||||
// CHECK-Bedingung der Datenbank erlaubt das ausdrücklich; die Prüfung
|
||||
// hier war strenger und hätte einen echten Fall abgewiesen.
|
||||
const spalten = [...PERSON_SPALTEN, "Austritt", "Austrittsgrund"];
|
||||
const r = pruefe(
|
||||
[blatt("Personen", spalten, [[...person("1", "a@example.at", "60000001"), "01.03.2015", "Dienstantritt nicht erfolgt"]])],
|
||||
BESTAND
|
||||
);
|
||||
expect(r.fehler).toEqual([]);
|
||||
});
|
||||
|
||||
it("bindet die Wochenstunden an die Beschäftigungsart", () => {
|
||||
// Vollzeit sind genau 38,5 — die Datenbank hat dafür eine
|
||||
// CHECK-Bedingung. Ohne diese Prüfung bricht der Import erst beim
|
||||
// Schreiben ab, und die Meldung nennt keine Zeile.
|
||||
const spalten = [...PERSON_SPALTEN, "Beschäftigung", "Wochenstunden"];
|
||||
const falsch = pruefe(
|
||||
[blatt("Personen", spalten, [[...person("1", "a@example.at", "60000001"), "Vollzeit", "20,5"]])],
|
||||
BESTAND
|
||||
);
|
||||
expect(meldungen(falsch.fehler).join(" ")).toContain("Vollzeit sind genau 38,5");
|
||||
|
||||
const teilzeitOhne = pruefe(
|
||||
[blatt("Personen", spalten, [[...person("1", "a@example.at", "60000001"), "Teilzeit", ""]])],
|
||||
BESTAND
|
||||
);
|
||||
expect(meldungen(teilzeitOhne.fehler).join(" ")).toContain("Pflicht bei Teilzeit");
|
||||
|
||||
const gut = pruefe(
|
||||
[blatt("Personen", spalten, [[...person("1", "a@example.at", "60000001"), "Teilzeit", "20,5"]])],
|
||||
BESTAND
|
||||
);
|
||||
expect(gut.fehler).toEqual([]);
|
||||
});
|
||||
|
||||
it("lässt nur Titel aus der hinterlegten Liste zu", () => {
|
||||
const spalten = [...PERSON_SPALTEN, "Titel vorangestellt"];
|
||||
const erfunden = pruefe(
|
||||
[blatt("Personen", spalten, [[...person("1", "a@example.at", "60000001"), "Doktor"]])],
|
||||
BESTAND
|
||||
);
|
||||
expect(meldungen(erfunden.fehler).join(" ")).toContain("Doktor");
|
||||
|
||||
const echt = pruefe([blatt("Personen", spalten, [[...person("1", "a@example.at", "60000001"), "Mag."]])], BESTAND);
|
||||
expect(echt.fehler).toEqual([]);
|
||||
});
|
||||
|
||||
it("verlangt ein Ende nur bei befristeten Verträgen — und dort immer", () => {
|
||||
|
||||
Reference in New Issue
Block a user