Open lesson

Mission: save the erased record

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

Keep two successive versions of a label without gaps or overlaps and find the one valid at a chosen time.

Voss shows a screenshot of the current entry, only SHELL-02, and claims the registry never named the prototype. Mara retrieves the earlier L1 version. Imani asks you to prepare a practice chronology without altering this evidence: L1 starts April 1 and the change to L2 applies April 12 at 20:00 UTC. The dossier deadline is fictional; no countdown blocks this lesson.

Your mission

  1. Write both complete history rows with their [start, end) periods.
  2. Explain what an update that overwrites L1 would do instead of creating L2.
  3. Explain BEGIN and COMMIT around closing one version and opening the next.
  4. Name two checks needed before using this history in a report.

How to check your work

  • L1 ends at 20:00 exclusive; L2 begins at 20:00 inclusive and remains open.
  • Overwriting L1 loses the old description.
  • The two writes should be committed together.
  • One current version and no overlapping period or unexplained gap.

Course example

CREATE TABLE label_history (
    version_id TEXT PRIMARY KEY,
    vehicle_label TEXT NOT NULL,
    physical_asset TEXT NOT NULL,
    valid_from TEXT NOT NULL,
    valid_to TEXT,
    CHECK (valid_to IS NULL OR valid_from < valid_to),
    UNIQUE (vehicle_label, valid_from)
);
INSERT INTO label_history VALUES
    ('L1', 'NOCTIS-01', 'PROTOTYPE-01', '2026-04-01T00:00:00Z', NULL);

BEGIN;
UPDATE label_history
SET valid_to = '2026-04-12T20:00:00Z'
WHERE version_id = 'L1' AND valid_to IS NULL;
INSERT INTO label_history VALUES
    ('L2', 'NOCTIS-01', 'SHELL-02', '2026-04-12T20:00:00Z', NULL);
COMMIT;

SELECT version_id, physical_asset, valid_from, valid_to
FROM label_history
ORDER BY valid_from;
SELECT COUNT(*) AS current_versions
FROM label_history
WHERE vehicle_label = 'NOCTIS-01' AND valid_to IS NULL;

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 both complete history rows with their [start, end) periods.
-- Explain what an update that overwrites L1 would do instead of creating L2.
-- Explain BEGIN and COMMIT around closing one version and opening the next.
-- Name two checks needed before using this history in a report.

exemple.sql

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

CREATE TABLE label_history (
    version_id TEXT PRIMARY KEY,
    vehicle_label TEXT NOT NULL,
    physical_asset TEXT NOT NULL,
    valid_from TEXT NOT NULL,
    valid_to TEXT,
    CHECK (valid_to IS NULL OR valid_from < valid_to),
    UNIQUE (vehicle_label, valid_from)
);
INSERT INTO label_history VALUES
    ('L1', 'NOCTIS-01', 'PROTOTYPE-01', '2026-04-01T00:00:00Z', NULL);

BEGIN;
UPDATE label_history
SET valid_to = '2026-04-12T20:00:00Z'
WHERE version_id = 'L1' AND valid_to IS NULL;
INSERT INTO label_history VALUES
    ('L2', 'NOCTIS-01', 'SHELL-02', '2026-04-12T20:00:00Z', NULL);
COMMIT;

SELECT version_id, physical_asset, valid_from, valid_to
FROM label_history
ORDER BY valid_from;
SELECT COUNT(*) AS current_versions
FROM label_history
WHERE vehicle_label = 'NOCTIS-01' AND valid_to IS NULL;