feat: add editable ordered trail pages
This commit is contained in:
20
server/migrations/015_seed_trails_from_legacy_categories.sql
Normal file
20
server/migrations/015_seed_trails_from_legacy_categories.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- Course categories were previously presented as trilhas but only stored a
|
||||
-- label. Turn every existing label into a real ordered trilha without moving
|
||||
-- or deleting any course.
|
||||
insert into learning_paths (title, description, status, published_at)
|
||||
select category.name, '', 'draft', null
|
||||
from course_categories category
|
||||
where not exists (
|
||||
select 1 from learning_paths path where lower(path.title) = lower(category.name)
|
||||
);
|
||||
|
||||
insert into learning_path_courses (learning_path_id, course_id, position)
|
||||
select path.id, course.id, ranked.position
|
||||
from (
|
||||
select id, category, row_number() over (partition by category order by published_at nulls last, title, id)::integer as position
|
||||
from courses
|
||||
where status <> 'archived'
|
||||
) ranked
|
||||
join courses course on course.id = ranked.id
|
||||
join learning_paths path on lower(path.title) = lower(ranked.category)
|
||||
on conflict (learning_path_id, course_id) do nothing;
|
||||
Reference in New Issue
Block a user