Sync LMS backend source
This commit is contained in:
@@ -0,0 +1,216 @@
|
||||
UPDATE "courses"
|
||||
SET "organization_name" = '퓨처드라이브',
|
||||
"updated_at" = CURRENT_TIMESTAMP
|
||||
WHERE "slug" = 'futuredrive-autonomy-basic'
|
||||
AND "organization_name" = '공통';
|
||||
|
||||
CREATE TEMP TABLE "_course_split_source" AS
|
||||
SELECT "id" AS source_course_id
|
||||
FROM "courses"
|
||||
WHERE "slug" = 'futuredrive-autonomy-basic'
|
||||
LIMIT 1;
|
||||
|
||||
INSERT INTO "courses" ("slug", "title", "subtitle", "description", "organization_name", "teacher_id", "is_active", "updated_at")
|
||||
SELECT
|
||||
'yeungnam-autonomy-basic',
|
||||
source."title",
|
||||
source."subtitle",
|
||||
source."description",
|
||||
'영남대학교',
|
||||
teacher."id",
|
||||
true,
|
||||
CURRENT_TIMESTAMP
|
||||
FROM "_course_split_source" split
|
||||
JOIN "courses" source ON source."id" = split.source_course_id
|
||||
JOIN "users" teacher ON teacher."email" = 'teacher@yu.ac.kr'
|
||||
ON CONFLICT ("slug") DO UPDATE
|
||||
SET "title" = EXCLUDED."title",
|
||||
"subtitle" = EXCLUDED."subtitle",
|
||||
"description" = EXCLUDED."description",
|
||||
"organization_name" = EXCLUDED."organization_name",
|
||||
"teacher_id" = EXCLUDED."teacher_id",
|
||||
"is_active" = true,
|
||||
"updated_at" = CURRENT_TIMESTAMP;
|
||||
|
||||
CREATE TEMP TABLE "_course_split_target" AS
|
||||
SELECT "id" AS target_course_id
|
||||
FROM "courses"
|
||||
WHERE "slug" = 'yeungnam-autonomy-basic'
|
||||
LIMIT 1;
|
||||
|
||||
INSERT INTO "course_platforms" ("course_id", "platform_id", "status", "action", "state", "sort_order", "updated_at")
|
||||
SELECT target.target_course_id, platform."platform_id", platform."status", platform."action", platform."state", platform."sort_order", CURRENT_TIMESTAMP
|
||||
FROM "course_platforms" platform
|
||||
JOIN "_course_split_source" source ON source.source_course_id = platform."course_id"
|
||||
CROSS JOIN "_course_split_target" target
|
||||
ON CONFLICT ("course_id", "platform_id") DO UPDATE
|
||||
SET "status" = EXCLUDED."status",
|
||||
"action" = EXCLUDED."action",
|
||||
"state" = EXCLUDED."state",
|
||||
"sort_order" = EXCLUDED."sort_order",
|
||||
"updated_at" = CURRENT_TIMESTAMP;
|
||||
|
||||
INSERT INTO "course_environment_profiles" ("course_id", "week", "platform_key", "profile_type", "name", "config", "enabled", "updated_at")
|
||||
SELECT target.target_course_id, profile."week", profile."platform_key", profile."profile_type", profile."name", profile."config", profile."enabled", CURRENT_TIMESTAMP
|
||||
FROM "course_environment_profiles" profile
|
||||
JOIN "_course_split_source" source ON source.source_course_id = profile."course_id"
|
||||
CROSS JOIN "_course_split_target" target
|
||||
ON CONFLICT ("course_id", "week", "platform_key") DO UPDATE
|
||||
SET "profile_type" = EXCLUDED."profile_type",
|
||||
"name" = EXCLUDED."name",
|
||||
"config" = EXCLUDED."config",
|
||||
"enabled" = EXCLUDED."enabled",
|
||||
"updated_at" = CURRENT_TIMESTAMP;
|
||||
|
||||
INSERT INTO "course_weeks" ("course_id", "week", "title", "tags", "progress", "state", "duration", "github", "overview", "deliverable", "updated_at")
|
||||
SELECT target.target_course_id, week."week", week."title", week."tags", week."progress", week."state", week."duration", week."github", week."overview", week."deliverable", CURRENT_TIMESTAMP
|
||||
FROM "course_weeks" week
|
||||
JOIN "_course_split_source" source ON source.source_course_id = week."course_id"
|
||||
CROSS JOIN "_course_split_target" target
|
||||
ON CONFLICT ("course_id", "week") DO UPDATE
|
||||
SET "title" = EXCLUDED."title",
|
||||
"tags" = EXCLUDED."tags",
|
||||
"progress" = EXCLUDED."progress",
|
||||
"state" = EXCLUDED."state",
|
||||
"duration" = EXCLUDED."duration",
|
||||
"github" = EXCLUDED."github",
|
||||
"overview" = EXCLUDED."overview",
|
||||
"deliverable" = EXCLUDED."deliverable",
|
||||
"updated_at" = CURRENT_TIMESTAMP;
|
||||
|
||||
CREATE TEMP TABLE "_course_split_week_map" AS
|
||||
SELECT source_week."id" AS source_week_id, target_week."id" AS target_week_id, source_week."week"
|
||||
FROM "course_weeks" source_week
|
||||
JOIN "_course_split_source" source ON source.source_course_id = source_week."course_id"
|
||||
JOIN "_course_split_target" target ON true
|
||||
JOIN "course_weeks" target_week ON target_week."course_id" = target.target_course_id AND target_week."week" = source_week."week";
|
||||
|
||||
INSERT INTO "course_week_topics" ("week_id", "sort_order", "title", "detail")
|
||||
SELECT week_map.target_week_id, topic."sort_order", topic."title", topic."detail"
|
||||
FROM "course_week_topics" topic
|
||||
JOIN "_course_split_week_map" week_map ON week_map.source_week_id = topic."week_id"
|
||||
ON CONFLICT ("week_id", "sort_order") DO UPDATE
|
||||
SET "title" = EXCLUDED."title",
|
||||
"detail" = EXCLUDED."detail";
|
||||
|
||||
INSERT INTO "course_week_practices" ("week_id", "sort_order", "title", "description")
|
||||
SELECT week_map.target_week_id, practice."sort_order", practice."title", practice."description"
|
||||
FROM "course_week_practices" practice
|
||||
JOIN "_course_split_week_map" week_map ON week_map.source_week_id = practice."week_id"
|
||||
ON CONFLICT ("week_id", "sort_order") DO UPDATE
|
||||
SET "title" = EXCLUDED."title",
|
||||
"description" = EXCLUDED."description";
|
||||
|
||||
INSERT INTO "course_week_modules" ("week_id", "sort_order", "category", "name", "folder_name", "template_repository_url", "docker_image", "updated_at")
|
||||
SELECT week_map.target_week_id, module."sort_order", module."category", module."name", module."folder_name", module."template_repository_url", module."docker_image", CURRENT_TIMESTAMP
|
||||
FROM "course_week_modules" module
|
||||
JOIN "_course_split_week_map" week_map ON week_map.source_week_id = module."week_id"
|
||||
ON CONFLICT ("week_id", "folder_name") DO UPDATE
|
||||
SET "sort_order" = EXCLUDED."sort_order",
|
||||
"category" = EXCLUDED."category",
|
||||
"name" = EXCLUDED."name",
|
||||
"template_repository_url" = EXCLUDED."template_repository_url",
|
||||
"docker_image" = EXCLUDED."docker_image",
|
||||
"updated_at" = CURRENT_TIMESTAMP;
|
||||
|
||||
CREATE TEMP TABLE "_course_split_module_map" AS
|
||||
SELECT source_module."id" AS source_module_id, target_module."id" AS target_module_id, week_map.source_week_id, week_map.target_week_id
|
||||
FROM "course_week_modules" source_module
|
||||
JOIN "_course_split_week_map" week_map ON week_map.source_week_id = source_module."week_id"
|
||||
JOIN "course_week_modules" target_module ON target_module."week_id" = week_map.target_week_id AND target_module."folder_name" = source_module."folder_name";
|
||||
|
||||
INSERT INTO "student_enrollments" ("user_id", "course_id", "organization_id", "organization_name", "status", "removed_at", "updated_at")
|
||||
SELECT enrollment."user_id", target.target_course_id, enrollment."organization_id", enrollment."organization_name", enrollment."status", enrollment."removed_at", CURRENT_TIMESTAMP
|
||||
FROM "student_enrollments" enrollment
|
||||
JOIN "_course_split_source" source ON source.source_course_id = enrollment."course_id"
|
||||
CROSS JOIN "_course_split_target" target
|
||||
WHERE enrollment."organization_name" = '영남대학교'
|
||||
ON CONFLICT ("user_id", "course_id") DO UPDATE
|
||||
SET "organization_id" = EXCLUDED."organization_id",
|
||||
"organization_name" = EXCLUDED."organization_name",
|
||||
"status" = EXCLUDED."status",
|
||||
"removed_at" = EXCLUDED."removed_at",
|
||||
"updated_at" = CURRENT_TIMESTAMP;
|
||||
|
||||
DELETE FROM "student_enrollments" enrollment
|
||||
USING "_course_split_source" source
|
||||
WHERE enrollment."course_id" = source.source_course_id
|
||||
AND enrollment."organization_name" = '영남대학교';
|
||||
|
||||
INSERT INTO "course_student_progress" ("course_id", "user_id", "completed_weeks", "total_weeks", "learning_hours", "commit_count", "average_score", "updated_at")
|
||||
SELECT target.target_course_id, progress."user_id", progress."completed_weeks", progress."total_weeks", progress."learning_hours", progress."commit_count", progress."average_score", CURRENT_TIMESTAMP
|
||||
FROM "course_student_progress" progress
|
||||
JOIN "_course_split_source" source ON source.source_course_id = progress."course_id"
|
||||
JOIN "users" student ON student."id" = progress."user_id"
|
||||
CROSS JOIN "_course_split_target" target
|
||||
WHERE student."primary_organization_name" = '영남대학교'
|
||||
ON CONFLICT ("course_id", "user_id") DO UPDATE
|
||||
SET "completed_weeks" = EXCLUDED."completed_weeks",
|
||||
"total_weeks" = EXCLUDED."total_weeks",
|
||||
"learning_hours" = EXCLUDED."learning_hours",
|
||||
"commit_count" = EXCLUDED."commit_count",
|
||||
"average_score" = EXCLUDED."average_score",
|
||||
"updated_at" = CURRENT_TIMESTAMP;
|
||||
|
||||
DELETE FROM "course_student_progress" progress
|
||||
USING "_course_split_source" source, "users" student
|
||||
WHERE progress."course_id" = source.source_course_id
|
||||
AND student."id" = progress."user_id"
|
||||
AND student."primary_organization_name" = '영남대학교';
|
||||
|
||||
UPDATE "instructor_curriculum_settings" setting
|
||||
SET "course_id" = target.target_course_id,
|
||||
"updated_at" = CURRENT_TIMESTAMP
|
||||
FROM "_course_split_source" source, "_course_split_target" target
|
||||
WHERE setting."course_id" = source.source_course_id
|
||||
AND setting."organization_name" = '영남대학교';
|
||||
|
||||
INSERT INTO "instructor_curriculum_week_overrides" ("organization_id", "organization_name", "course_id", "week", "title", "duration", "overview", "deliverable", "topics", "topic_details", "updated_at")
|
||||
SELECT override."organization_id", override."organization_name", target.target_course_id, override."week", override."title", override."duration", override."overview", override."deliverable", override."topics", override."topic_details", CURRENT_TIMESTAMP
|
||||
FROM "instructor_curriculum_week_overrides" override
|
||||
JOIN "_course_split_source" source ON source.source_course_id = override."course_id"
|
||||
CROSS JOIN "_course_split_target" target
|
||||
WHERE override."organization_name" = '영남대학교'
|
||||
ON CONFLICT ("organization_name", "course_id", "week") DO UPDATE
|
||||
SET "title" = EXCLUDED."title",
|
||||
"duration" = EXCLUDED."duration",
|
||||
"overview" = EXCLUDED."overview",
|
||||
"deliverable" = EXCLUDED."deliverable",
|
||||
"topics" = EXCLUDED."topics",
|
||||
"topic_details" = EXCLUDED."topic_details",
|
||||
"updated_at" = CURRENT_TIMESTAMP;
|
||||
|
||||
DELETE FROM "instructor_curriculum_week_overrides" override
|
||||
USING "_course_split_source" source
|
||||
WHERE override."course_id" = source.source_course_id
|
||||
AND override."organization_name" = '영남대학교';
|
||||
|
||||
UPDATE "studio_repositories" repository
|
||||
SET "week_id" = module_map.target_week_id,
|
||||
"module_id" = module_map.target_module_id,
|
||||
"updated_at" = CURRENT_TIMESTAMP
|
||||
FROM "_course_split_module_map" module_map, "users" student
|
||||
WHERE repository."module_id" = module_map.source_module_id
|
||||
AND repository."user_id" = student."id"
|
||||
AND student."primary_organization_name" = '영남대학교';
|
||||
|
||||
UPDATE "chat_threads" thread
|
||||
SET "course_id" = target.target_course_id,
|
||||
"updated_at" = CURRENT_TIMESTAMP
|
||||
FROM "_course_split_source" source
|
||||
JOIN "_course_split_target" target ON true
|
||||
JOIN "users" student ON true
|
||||
WHERE thread."course_id" = source.source_course_id
|
||||
AND student."id" = thread."student_id"
|
||||
AND student."primary_organization_name" = '영남대학교';
|
||||
|
||||
UPDATE "chat_threads" thread
|
||||
SET "week_id" = week_map.target_week_id,
|
||||
"updated_at" = CURRENT_TIMESTAMP
|
||||
FROM "_course_split_week_map" week_map
|
||||
JOIN "_course_split_target" target ON true
|
||||
JOIN "users" student ON true
|
||||
WHERE thread."course_id" = target.target_course_id
|
||||
AND thread."week_id" = week_map.source_week_id
|
||||
AND student."id" = thread."student_id"
|
||||
AND student."primary_organization_name" = '영남대학교';
|
||||
Reference in New Issue
Block a user