feat: course section reordering & migration to course v2 (#437)

* feat: reorder sections and lessons gracefully

* convert course into version 2

* feat: get next and prev working
This commit is contained in:
Rotimi Best
2024-08-17 17:10:15 +01:00
committed by GitHub
parent e18b4ca1b1
commit 1c9dc004a0
17 changed files with 425 additions and 143 deletions
@@ -124,4 +124,22 @@ using (is_user_in_group_with_role(( SELECT course.group_id
with check (is_user_in_group_with_role(( SELECT course.group_id
FROM course
WHERE (course.id = lesson_section.course_id)
LIMIT 1)));
LIMIT 1)));
CREATE
OR REPLACE FUNCTION convert_course_to_v2 (course_id uuid) RETURNS void AS $$
DECLARE
new_section_id bigint;
BEGIN
UPDATE course
SET version = 'V2'
WHERE id = course_id;
INSERT INTO lesson_section (title, course_id) VALUES ('First Section [edit me]', course_id) RETURNING id INTO new_section_id;
UPDATE lesson
SET section_id = new_section_id
WHERE course_id = course_id;
END;
$$ LANGUAGE plpgsql;