From 497819c7fd64d907a90a83040076637bdb8d2cd7 Mon Sep 17 00:00:00 2001 From: Birk Date: Sun, 14 Dec 2025 20:28:38 +0300 Subject: [PATCH] migration to ckickhouse --- .../task_220_migration_to_ckick.sql | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 ybirk/clickhouse/task_220_migration_to_ckick.sql diff --git a/ybirk/clickhouse/task_220_migration_to_ckick.sql b/ybirk/clickhouse/task_220_migration_to_ckick.sql new file mode 100644 index 0000000..141e897 --- /dev/null +++ b/ybirk/clickhouse/task_220_migration_to_ckick.sql @@ -0,0 +1,80 @@ +CREATE TABLE ybirk.core_user ( + user_id Int32, + name String, + age Int32, + email String, + registration_date Date +) +ENGINE = MergeTree +ORDER BY user_id; + +CREATE TABLE ybirk.core_course ( + course_id Int32, + title String, + category String +) +ENGINE = MergeTree +ORDER BY course_id; + +CREATE TABLE ybirk.core_lesson ( + lesson_id Int32, + title String, + duration_min Int32, + course_id Int32 +) +ENGINE = MergeTree +ORDER BY lesson_id; + +CREATE TABLE ybirk.core_fact_lesson_views ( + user_id Int32, + lesson_id Int32, + course_id Int32, + viewed_at DateTime64(3) +) +ENGINE = MergeTree +ORDER BY user_id; + +CREATE TABLE ybirk.core_enrollments ( + id Int32, + user_id Int32, + course_id Int32, + enrolled_at Date +) +ENGINE = MergeTree +ORDER BY user_id; + +------------------------- + +INSERT INTO ybirk.core_user (user_id, name, age, email, registration_date) VALUES +(1, 'Alice', 25, 'alice@mail.com', '2023-01-10'), +(2, 'Bob', 30, 'bob@gmail.com', '2023-02-05'), +(3, 'Charlie', 22, 'charlie@mail.com', '2023-02-20'), +(4, 'Diana', 28, 'diana@mail.com', '2023-03-01'), +(5, 'Ethan', 35, 'ethan@gmail.com', '2023-03-10'); + +INSERT INTO ybirk.core_course (course_id, title, category) VALUES +(1, 'SQL для начинающих', 'data'), +(2, 'Python для анализа данных', 'programming'), +(3, 'BI с нуля', 'business'); + +INSERT INTO ybirk.core_lesson (lesson_id, course_id, title, duration_min) VALUES +(1, 1, 'SELECT и FROM', 10), +(2, 1, 'JOIN', 15), +(3, 2, 'Pandas', 20), +(4, 3, 'Основы BI', 12), +(5, 3, 'Метрики и дашборды', 18); + +INSERT INTO ybirk.core_fact_lesson_views (user_id, lesson_id, course_id, viewed_at) VALUES +(1, 1, 1, '2023-01-16 10:00:00'), +(1, 2, 1, '2023-01-16 10:15:00'), +(2, 1, 1, '2023-01-21 09:00:00'), +(3, 3, 2, '2023-03-06 12:00:00'), +(4, 4, 3, '2023-04-02 10:00:00'), +(4, 5, 3, '2023-04-03 10:00:00'); + +INSERT INTO ybirk.core_enrollments (id, user_id, course_id, enrolled_at) VALUES +(1, 1, 1, '2023-01-15'), +(2, 1, 2, '2023-02-01'), +(3, 2, 1, '2023-01-20'), +(4, 3, 2, '2023-03-05'), +(5, 4, 3, '2023-04-01'); \ No newline at end of file