Brief
Use a transaction to test then cancel writes, commit only the intended state and reject a second record with the same event key.
In the story, Voss wants to produce another row bearing your ID. Imani gives you a SQLite copy whose rule says that one event_key may appear only once. A1 / EXIT-7 has already been committed. Mara asks you to try inserting A2 / EXIT-7 inside a transaction without changing the original register, then show state after failure.
Your mission
- Write the schema rule forbidding two rows with
EXIT-7. - Describe the expected result of attempting to insert A2 with that event.
- Say how to end the failed test and what should remain visible.
- Explain why the demonstration still cannot prove who created A1 in the real register.
How to check your work
- The rule is
UNIQUE(event_key)with a present value. - A2 is rejected although its
iddiffers from A1. - Handle the error, close the test with
ROLLBACK, and retain committed A1 alone. - The constraint protects a rule in a copy; identity and authenticity need other evidence.
Course example
CREATE TABLE authorizations (
id TEXT PRIMARY KEY,
event_key TEXT NOT NULL UNIQUE,
actor_id TEXT NOT NULL
);
BEGIN;
INSERT INTO authorizations (id, event_key, actor_id)
VALUES ('A1', 'EXIT-7', 'HERO-ID');
INSERT INTO authorizations (id, event_key, actor_id)
VALUES ('TEMP', 'DRAFT', 'TEST');
ROLLBACK;
SELECT COUNT(*) AS rows_after_rollback FROM authorizations;
BEGIN;
INSERT INTO authorizations (id, event_key, actor_id)
VALUES ('A1', 'EXIT-7', 'HERO-ID');
COMMIT;
SELECT id, event_key FROM authorizations;