-- database/migrations/001_lesson_requirements_unique.sql
-- Run this once against an existing GeoVic EduPro database (one that was
-- installed from the original database/schema.sql). If you are installing
-- fresh, this constraint is already worth adding directly to schema.sql
-- going forward — but for anyone who already ran the original file, run
-- this as a follow-up migration instead of re-running schema.sql.
--
-- Why: a stream should have exactly one lesson requirement (one teacher,
-- one lessons-per-week count) per subject per term. Without this, the
-- Lesson Requirements screen could silently create duplicate/conflicting
-- rows for the same stream+subject+term.

ALTER TABLE lesson_requirements
    ADD UNIQUE KEY uniq_term_stream_subject (term_id, stream_id, subject_id);
