oficina / fichas Public

Clone
git clone https://amadan.net/oficina/fichas

Plain git — no account needed to clone.

Download

Download this file

1-- Entries are immutable, and cards are deleted by being marked gone.
2--
3-- Both were true only by convention: there was no UpdateEntry, and
4-- DeleteCard set `gone` — but a stray `Save` on an entry_values row
5-- rewrote it, and a stray `Delete` on a card hard-deleted it AND cascaded
6-- its values, entries and refs away while the events survived pointing at
7-- nothing. "No function exists for it" is not an invariant.
8--
9-- Written by hand rather than generated: `rastrillo migration generate`
10-- diffs Models against migrations and knows nothing about triggers, so it
11-- would neither write these nor notice them missing.
12
13-- §3: an entry is a fact about a past moment. A correction is a new entry
14-- that supersedes, never an edit.
15CREATE TRIGGER entries_are_immutable
16BEFORE UPDATE ON entries
17BEGIN
18 SELECT RAISE(ABORT, 'entries are immutable: write a new entry that supersedes this one');
19END;
20
21CREATE TRIGGER entry_values_are_immutable
22BEFORE UPDATE ON entry_values
23BEGIN
24 SELECT RAISE(ABORT, 'entry values are immutable: write a new entry that supersedes this one');
25END;
26
27-- An entry may not be removed either: its event would outlive it and name
28-- a row that is not there.
29CREATE TRIGGER entries_are_not_deleted
30BEFORE DELETE ON entries
31WHEN (SELECT COUNT(*) FROM cards WHERE cards.id = OLD.card_id) > 0
32BEGIN
33 SELECT RAISE(ABORT, 'entries are not deleted: mark the card gone instead');
34END;
35
36-- §5 and suite ruling 14: retirement is by feed, never by erasure. A hard
37-- delete here would take the card's values, entries and refs with it
38-- through the cascades, silently and completely.
39CREATE TRIGGER cards_are_not_hard_deleted
40BEFORE DELETE ON cards
41BEGIN
42 SELECT RAISE(ABORT, 'cards are not deleted: set gone, which is what DeleteCard does');
43END;
44