Context
V-L2-L1 prevents forks at the application layer. Defence in depth:
make forks structurally impossible by adding a DB-level UNIQUE
constraint on (entity_id, previous_hash). A second writer that
somehow sneaks past the chain_head lock still cannot insert because
the unique constraint rejects the second row with the same predecessor.
What to do
In src/codegen/overlay.rs::generate_provenance_table, add:
CREATE UNIQUE INDEX IF NOT EXISTS ux_provenance_chain
ON verisimdb_provenance_log(entity_id, previous_hash);
(Genesis records all have previous_hash = ''; one genesis per
entity is exactly what we want, so the unique index correctly
forbids duplicate geneses too.)
In tests, assert that the generated DDL contains the unique
index, and that an attempted duplicate insert fails with a
constraint violation.
Acceptance
Context
V-L2-L1 prevents forks at the application layer. Defence in depth:
make forks structurally impossible by adding a DB-level UNIQUE
constraint on
(entity_id, previous_hash). A second writer thatsomehow sneaks past the chain_head lock still cannot insert because
the unique constraint rejects the second row with the same predecessor.
What to do
In
src/codegen/overlay.rs::generate_provenance_table, add:(Genesis records all have
previous_hash = ''; one genesis perentity is exactly what we want, so the unique index correctly
forbids duplicate geneses too.)
In tests, assert that the generated DDL contains the unique
index, and that an attempted duplicate insert fails with a
constraint violation.
Acceptance
appends; one succeeds, the other gets a constraint-violation
error and retries against the new head (graceful)
model doc