-- scenario_attempts — new capability, did not exist before Phase 2B. The old model only ever -- kept aggregate progress (status + a bare attempts counter); this is a per-attempt log, -- giving instructors real "validation outcomes where recorded" visibility instead of just a -- final status. -- -- hint_count is deliberately nullable and unpopulated: the existing Lab engine's hints are -- static UI content only (frontend/src/components/ScenarioPanel.jsx renders them from the -- scenario JSON) — nothing server-side ever records a hint being viewed. Do not invent a -- number here. If hint-view tracking is added to the Lab engine later, this column is ready -- for it without a schema change. CREATE TABLE IF NOT EXISTS scenario_attempts ( attempt_id BIGSERIAL PRIMARY KEY, student_id TEXT NOT NULL REFERENCES students(student_id), scenario_id TEXT NOT NULL, environment_id UUID REFERENCES environments(environment_id), started_at TIMESTAMPTZ, completed_at TIMESTAMPTZ, result TEXT NOT NULL, -- 'passed' | 'failed' validation_count INTEGER, -- number of validation checks run this attempt hint_count INTEGER, -- NULL — not measurable today, see note above metadata JSONB, created_at TIMESTAMPTZ NOT NULL DEFAULT now() ); CREATE INDEX IF NOT EXISTS idx_attempts_student ON scenario_attempts(student_id); CREATE INDEX IF NOT EXISTS idx_attempts_scenario ON scenario_attempts(scenario_id); CREATE INDEX IF NOT EXISTS idx_attempts_environment ON scenario_attempts(environment_id); CREATE INDEX IF NOT EXISTS idx_attempts_created ON scenario_attempts(created_at);