Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add external id table #521

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tutoraspects/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
"edx-event-routing-backends==v7.0.1",
],
),
("EVENT_SINK_CLICKHOUSE_MODELS", ["course_overviews", "user_profile"]),
(
"EVENT_SINK_CLICKHOUSE_MODELS",
["course_overviews", "user_profile", "external_id"],
),
("EVENT_SINK_CLICKHOUSE_PII_MODELS", ["user_profile", "external_id"]),
# Turning on this flag will store personally identifiable information
# in the ClickHouse database. Make sure that you understand the legal
Expand Down Expand Up @@ -93,6 +96,7 @@
("ASPECTS_EVENT_SINK_RELATIONSHIPS_TABLE", "course_relationships"),
("ASPECTS_EVENT_SINK_OVERVIEWS_TABLE", "course_overviews"),
("ASPECTS_EVENT_SINK_USER_PROFILE_TABLE", "user_profile"),
("ASPECTS_EVENT_SINK_EXTERNAL_ID_TABLE", "external_id"),
("ASPECTS_EVENT_SINK_CLICKHOUSE_TIMEOUT_SECS", "5"),
("ASPECTS_EVENT_SINK_RECENT_BLOCKS_TABLE", "most_recent_course_blocks"),
("ASPECTS_EVENT_SINK_RECENT_BLOCKS_MV", "most_recent_course_blocks_mv"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
create external_id sink table
"""
from alembic import op


revision = "0026"
down_revision = "0025"
branch_labels = None
depends_on = None
on_cluster = " ON CLUSTER '{{CLICKHOUSE_CLUSTER_NAME}}' " if "{{CLICKHOUSE_CLUSTER_NAME}}" else ""
engine = "ReplicatedReplacingMergeTree" if "{{CLICKHOUSE_CLUSTER_NAME}}" else "ReplacingMergeTree"


def upgrade():
op.execute(
f"""
CREATE TABLE IF NOT EXISTS {{ ASPECTS_EVENT_SINK_DATABASE }}.{{ ASPECTS_EVENT_SINK_EXTERNAL_ID_TABLE }}
{on_cluster}
(
`external_user_id` UUID NOT NULL,
`external_id_type` String,
`username` String,
`user_id` Int32,
`dump_id` UUID NOT NULL,
`time_last_dumped` String NOT NULL
)
ENGINE = {engine}
PRIMARY KEY (external_user_id, time_last_dumped)
Ian2012 marked this conversation as resolved.
Show resolved Hide resolved
PARTITION BY user_id MOD 100
ORDER BY (external_user_id, time_last_dumped)
"""
)


def downgrade():
op.execute(
"DROP TABLE IF EXISTS {{ ASPECTS_EVENT_SINK_DATABASE }}.{{ ASPECTS_EVENT_SINK_EXTERNAL_ID_TABLE }}"
f"{on_cluster}"
)