From 55caee7dc665e3c896b686e6d53543cd95d53f63 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Fri, 16 Feb 2024 11:10:56 -0500 Subject: [PATCH] feat: add get_org_from_ccx_course_url function --- .../alembic/versions/0033_ccx_function.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tutoraspects/templates/aspects/apps/aspects/migrations/alembic/versions/0033_ccx_function.py diff --git a/tutoraspects/templates/aspects/apps/aspects/migrations/alembic/versions/0033_ccx_function.py b/tutoraspects/templates/aspects/apps/aspects/migrations/alembic/versions/0033_ccx_function.py new file mode 100644 index 000000000..1e6682a2a --- /dev/null +++ b/tutoraspects/templates/aspects/apps/aspects/migrations/alembic/versions/0033_ccx_function.py @@ -0,0 +1,27 @@ +""" +Create the get_org_from_ccx_course_url function to support CCX courses +""" +from alembic import op + + +revision = "0033" +down_revision = "0032" +branch_labels = None +depends_on = None +on_cluster = " ON CLUSTER '{{CLICKHOUSE_CLUSTER_NAME}}' " if "{{CLICKHOUSE_CLUSTER_NAME}}" else "" + +def upgrade(): + op.execute( + f""" + CREATE OR REPLACE FUNCTION get_org_from_ccx_course_url {on_cluster} + AS ( + course_url) -> + nullIf(EXTRACT(course_url, 'ccx-v1:([a-zA-Z0-9]*)'), ''); + + """ + ) + + + +def downgrade(): + op.execute("DROP FUNCTION IF EXISTS get_org_from_ccx_course_url;")