CREATE TABLE IF NOT EXISTS lesson_type_template_visibility (
    lesson_type_id INTEGER NOT NULL,
    template_id INTEGER NOT NULL,
    PRIMARY KEY (lesson_type_id, template_id),
    FOREIGN KEY (lesson_type_id) REFERENCES lesson_types (id) ON DELETE CASCADE,
    FOREIGN KEY (template_id) REFERENCES license_class_templates (id) ON DELETE CASCADE
);

INSERT OR IGNORE INTO lesson_type_template_visibility (lesson_type_id, template_id)
SELECT lt.id, tpl.id
FROM lesson_types lt
JOIN license_class_templates tpl ON tpl.tenant_id = lt.tenant_id
WHERE lt.category = 'student';
