Open lesson

Mission: block the third false trace

Command palette

This mission workspace keeps code and notes in this browser tab. Export them before closing it. Running code is practice, not an automatic grade for the mission.

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

  1. Write the schema rule forbidding two rows with EXIT-7.
  2. Describe the expected result of attempting to insert A2 with that event.
  3. Say how to end the failed test and what should remain visible.
  4. 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 id differs 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;

Code

Use Tab to leave the editor. Ctrl+Enter runs the source. The lines beginning with -- are task reminders. SQL ignores them. Write your query beneath them.

SQL console

Loading laboratory…

Explore Python or SQL here; this is not an operating-system shell.

This is a disposable browser experiment. The code run here is not recorded as a completed mission.

Each command starts a fresh disposable worker: it runs a captured copy of your current source, then your command with the lesson fixtures. Changes are discarded afterward. Commands never save source or award XP. Ctrl+Enter executes the command.

Virtual workspace files

Source and declarative assets are readable here without JavaScript. Python input files are created at runtime; SQL setup initializes the disposable database.

source.sql

Current editor source. Inspection shows your current edits.

-- 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.

exemple.sql

Declarative lesson asset; this is not a file created in the Python filesystem.

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;