upgrade clickhouse

This commit is contained in:
FahadKhalid210 2024-04-29 16:27:45 +05:00 committed by Fahad Khalid
parent 3190feacb8
commit c84c912a3b
5 changed files with 53 additions and 8 deletions

View File

@ -0,0 +1 @@
- 💥[Feature] Upgrade Clickhouse version to `24.1.8.22` and fix query issues due to deprecation of Live views. (by @Fahadkhalid210)

View File

@ -0,0 +1,23 @@
RENAME TABLE _openedx_course_enrollments TO openedx_course_enrollments;
RENAME TABLE _openedx_user_profiles TO openedx_user_profiles;
RENAME TABLE _openedx_users TO openedx_users;
DROP TABLE course_enrollments;
CREATE VIEW course_enrollments AS
SELECT
openedx_course_enrollments.course_id AS course_id,
openedx_course_enrollments.created AS enrollment_created,
openedx_course_enrollments.is_active AS enrollment_is_active,
openedx_course_enrollments.mode AS enrollment_mode,
openedx_course_enrollments.user_id AS user_id,
openedx_users.username AS username,
openedx_users.email AS user_email,
openedx_user_profiles.year_of_birth AS user_year_of_birth,
openedx_user_profiles.gender AS user_gender,
openedx_user_profiles.level_of_education AS user_level_of_education,
openedx_user_profiles.city AS user_city,
openedx_user_profiles.state AS user_state,
openedx_user_profiles.country AS user_country
FROM openedx_course_enrollments
INNER JOIN openedx_user_profiles ON openedx_course_enrollments.user_id = openedx_user_profiles.user_id
INNER JOIN openedx_users ON openedx_course_enrollments.user_id = openedx_users.id;

View File

@ -0,0 +1,15 @@
RENAME TABLE _openedx_block_completion TO openedx_block_completion;
DROP TABLE course_block_completion;
CREATE VIEW course_block_completion AS
SELECT
openedx_block_completion.course_key AS course_id,
openedx_block_completion.block_key AS block_key,
openedx_block_completion.user_id AS user_id,
openedx_block_completion.completion AS completion,
course_blocks.position as position,
course_blocks.display_name as display_name,
course_blocks.full_name as full_name
FROM openedx_block_completion
INNER JOIN course_blocks ON openedx_block_completion.block_key = course_blocks.block_key;

View File

@ -1,11 +1,11 @@
# https://hub.docker.com/r/yandex/clickhouse-server/tags
FROM docker.io/yandex/clickhouse-server:22.1.3.7
# https://hub.docker.com/r/clickhouse/clickhouse-server/tags
FROM docker.io/clickhouse/clickhouse-server:24.1.8.22
# The clickhouse repo is currently unavailable in some parts of the world. If we don't
# remove this repo here then `apt update` will fail. Check if the problem is resolved with:
# curl https://repo.yandex.ru/clickhouse/deb/stable/
# The above command should be a 200, and not a 404.
RUN rm /etc/apt/sources.list.d/clickhouse.list
# RUN rm /etc/apt/sources.list.d/clickhouse.list
RUN apt update && apt install -y python3
COPY ./scripts /scripts
RUN chmod a+x /scripts/*

View File

@ -117,11 +117,17 @@ def grant_clickhouse_row_based_access(clickhouse_username, course_ids=None):
for table in make_clickhouse_query("SHOW TABLES").split("\n"):
if not table.startswith("_"):
make_clickhouse_query(
f"""GRANT SELECT ON {table} TO '{clickhouse_username}';"""
)
make_clickhouse_query(
f"""CREATE ROW POLICY OR REPLACE '{clickhouse_username}' ON {table} AS RESTRICTIVE FOR SELECT USING {condition} TO '{clickhouse_username}';"""
)
f"""GRANT SELECT ON {table} TO '{clickhouse_username}';"""
)
if table in ["openedx_users", "openedx_user_profiles", "openedx_block_completion"]:
make_clickhouse_query(
f"""CREATE ROW POLICY OR REPLACE '{clickhouse_username}' ON {table} AS RESTRICTIVE FOR SELECT USING 1 TO '{clickhouse_username}';"""
)
else:
make_clickhouse_query(
f"""CREATE ROW POLICY OR REPLACE '{clickhouse_username}' ON {table} AS RESTRICTIVE FOR SELECT USING {condition} TO '{clickhouse_username}';"""
)
def make_clickhouse_query(query):