Skip to content

Commit 14a21d8

Browse files
committed
refactor: reorder top-level materialized views
Also adds a docstring for the migration to explain the changes in plain language, rather than rely on developers reading through a large mass of SQL statements.
1 parent c9cf476 commit 14a21d8

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

tutoraspects/templates/aspects/apps/aspects/migrations/alembic/versions/0011_reorder_mvs.py tutoraspects/templates/aspects/apps/aspects/migrations/alembic/versions/0013_reorder_mvs.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
"""
2+
Updates:
3+
1. The ORDER BY clauses for each top-level materialized view include more relevant
4+
fields. Since these tables now use the ReplacingMergeTree engine, the ORDER BY
5+
fields are used to determine whether a row needs to be updated.
6+
2. The video playback events MV now uses an integer for the video position
7+
3. The emission_time fields now use the DateTime type, as we do not need sub-second
8+
granularity and so can save space by using a smaller data type.
9+
"""
110
from dataclasses import dataclass
211

312
from alembic import op
413

5-
revision = "0011"
6-
down_revision = "0010"
14+
revision = "0013"
15+
down_revision = "0012"
716
branch_labels = None
817
depends_on = None
918

@@ -46,7 +55,7 @@ class MvMigration:
4655
`enrollment_mode` LowCardinality(String)
4756
) ENGINE = ReplacingMergeTree
4857
PRIMARY KEY (org, course_key)
49-
ORDER BY (org, course_key, actor_id, emission_time, enrollment_mode, event_id);
58+
ORDER BY (org, course_key, emission_time, actor_id, enrollment_mode, event_id);
5059
"""
5160

5261

@@ -114,7 +123,7 @@ class MvMigration:
114123
`video_position` UInt32 NOT NULL
115124
) ENGINE = ReplacingMergeTree
116125
PRIMARY KEY (org, course_key, verb_id)
117-
ORDER BY (org, course_key, verb_id, actor_id, emission_time, video_position, event_id);
126+
ORDER BY (org, course_key, verb_id, emission_time, actor_id, video_position, event_id);
118127
"""
119128

120129

@@ -205,7 +214,7 @@ class MvMigration:
205214
`attempts` Int16
206215
) ENGINE = ReplacingMergeTree
207216
PRIMARY KEY (org, course_key, verb_id)
208-
ORDER BY (org, course_key, verb_id, actor_id, emission_time, object_id, responses, success, event_id);
217+
ORDER BY (org, course_key, verb_id, emission_time, actor_id, object_id, responses, success, event_id);
209218
"""
210219

211220

@@ -307,7 +316,7 @@ class MvMigration:
307316
`ending_point` String
308317
) ENGINE = ReplacingMergeTree
309318
PRIMARY KEY (org, course_key, object_type)
310-
ORDER BY (org, course_key, object_type, actor_id, emission_time, starting_position, event_id);
319+
ORDER BY (org, course_key, object_type, emission_time, actor_id, starting_position, event_id);
311320
"""
312321

313322

0 commit comments

Comments
 (0)