studysystem 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- studysystem/__init__.py +1 -0
- studysystem/assets/note-callouts.lua +100 -0
- studysystem/assets/note-no-html.lua +28 -0
- studysystem/assets/note.css +146 -0
- studysystem/cli.py +344 -0
- studysystem/dashboard.html +781 -0
- studysystem/dashboard.py +377 -0
- studysystem/db/__init__.py +1 -0
- studysystem/db/engine.py +158 -0
- studysystem/db/migrate.py +122 -0
- studysystem/db/migrations/env.py +59 -0
- studysystem/db/migrations/script.py.mako +29 -0
- studysystem/db/migrations/versions/0000_baseline.py +19 -0
- studysystem/db/migrations/versions/0001_the_whole_schema.py +1743 -0
- studysystem/db/migrations/versions/0002_semester_ignores_case.py +38 -0
- studysystem/db/migrations/versions/0003_course_vault_folder.py +26 -0
- studysystem/db/migrations/versions/0004_note_pdf_path.py +26 -0
- studysystem/db/migrations/versions/0005_tagging_kind.py +39 -0
- studysystem/db/migrations/versions/0006_practice_mode.py +36 -0
- studysystem/db/migrations/versions/0007_exam_prep_from.py +25 -0
- studysystem/db/migrations/versions/0008_more_papers_kind.py +37 -0
- studysystem/db/migrations/versions/0009_past_exam_month_date.py +28 -0
- studysystem/db/migrations/versions/0010_task_parts.py +70 -0
- studysystem/db/migrations/versions/0011_observation_kind.py +39 -0
- studysystem/db/migrations/versions/0012_profile_claim.py +52 -0
- studysystem/db/migrations/versions/0013_assumed_instructor_papers.py +40 -0
- studysystem/db/migrations/versions/0014_scan_confirmation.py +44 -0
- studysystem/db/migrations/versions/0015_practice_item_count.py +37 -0
- studysystem/db/migrations/versions/0016_timetable_patterns.py +102 -0
- studysystem/db/migrations/versions/0017_course_dropped.py +36 -0
- studysystem/db/migrations/versions/0018_syllabus_topics.py +82 -0
- studysystem/db/migrations/versions/0019_course_lab_group.py +36 -0
- studysystem/db/migrations/versions/0020_chapter_scope.py +61 -0
- studysystem/db/migrations/versions/0021_note_retired_at.py +28 -0
- studysystem/db/migrations/versions/0022_rescope.py +48 -0
- studysystem/db/migrations/versions/0023_backlog_reason.py +42 -0
- studysystem/db/migrations/versions/0024_guess_sensitivity.py +35 -0
- studysystem/db/migrations/versions/0025_shortfall_inputs.py +83 -0
- studysystem/db/migrations/versions/0026_trials_switch.py +36 -0
- studysystem/db/tables.py +1096 -0
- studysystem/demo.py +722 -0
- studysystem/errors.py +39 -0
- studysystem/server/__init__.py +83 -0
- studysystem/server/__main__.py +5 -0
- studysystem/services/__init__.py +1 -0
- studysystem/services/adherence.py +147 -0
- studysystem/services/assessments.py +171 -0
- studysystem/services/capacity.py +164 -0
- studysystem/services/claims.py +405 -0
- studysystem/services/course_folder.py +82 -0
- studysystem/services/courses.py +176 -0
- studysystem/services/coverage.py +121 -0
- studysystem/services/dashboard_key.py +102 -0
- studysystem/services/feedback.py +412 -0
- studysystem/services/forward_eval.py +65 -0
- studysystem/services/gate.py +77 -0
- studysystem/services/generation.py +2864 -0
- studysystem/services/ids.py +15 -0
- studysystem/services/intake.py +278 -0
- studysystem/services/launcher.py +455 -0
- studysystem/services/lookups.py +91 -0
- studysystem/services/materials.py +97 -0
- studysystem/services/note_markdown.py +241 -0
- studysystem/services/notes.py +396 -0
- studysystem/services/parts.py +65 -0
- studysystem/services/past_exams.py +115 -0
- studysystem/services/pdf_render.py +148 -0
- studysystem/services/pdf_worker.py +184 -0
- studysystem/services/plan.py +1300 -0
- studysystem/services/private_view.py +38 -0
- studysystem/services/profiles.py +544 -0
- studysystem/services/programs.py +16 -0
- studysystem/services/replacements.py +107 -0
- studysystem/services/rescope.py +277 -0
- studysystem/services/settings.py +50 -0
- studysystem/services/setup.py +235 -0
- studysystem/services/shortfall.py +443 -0
- studysystem/services/state.py +846 -0
- studysystem/services/statements.py +222 -0
- studysystem/services/study_loop.py +998 -0
- studysystem/services/summaries.py +369 -0
- studysystem/services/syllabus.py +138 -0
- studysystem/services/system_work.py +113 -0
- studysystem/services/taxonomy.py +459 -0
- studysystem/services/topics.py +477 -0
- studysystem/services/trials.py +201 -0
- studysystem/services/unconfirmed.py +95 -0
- studysystem/services/units.py +34 -0
- studysystem/services/users.py +53 -0
- studysystem/services/values.py +168 -0
- studysystem/startup.py +147 -0
- studysystem/tools/__init__.py +4 -0
- studysystem/tools/course_setup.py +185 -0
- studysystem/tools/dashboard.py +27 -0
- studysystem/tools/feedback.py +66 -0
- studysystem/tools/gate.py +24 -0
- studysystem/tools/generation.py +156 -0
- studysystem/tools/materials.py +32 -0
- studysystem/tools/notes.py +29 -0
- studysystem/tools/past_exams.py +51 -0
- studysystem/tools/ping.py +9 -0
- studysystem/tools/plan.py +40 -0
- studysystem/tools/profiles.py +94 -0
- studysystem/tools/results.py +77 -0
- studysystem/tools/study_loop.py +145 -0
- studysystem/tools/summaries.py +52 -0
- studysystem/tools/topics.py +143 -0
- studysystem-1.0.0.dist-info/METADATA +254 -0
- studysystem-1.0.0.dist-info/RECORD +112 -0
- studysystem-1.0.0.dist-info/WHEEL +4 -0
- studysystem-1.0.0.dist-info/entry_points.txt +3 -0
- studysystem-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""a course can be dropped - kept as history, gone from the plan and the week (D-217)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0017
|
|
4
|
+
Revises: 0016
|
|
5
|
+
Create Date: 2026-10-31
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0017"
|
|
12
|
+
down_revision = "0016"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# A nullable column with no CHECK: a plain ALTER TABLE ADD COLUMN on both engines, so `course`
|
|
17
|
+
# is not rebuilt and its expression index `ux_course_code` is never touched. No backfill: no
|
|
18
|
+
# course was dropped before this.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
op.add_column("course", sa.Column("dropped_at", sa.Text(), nullable=True))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def downgrade() -> None:
|
|
26
|
+
# Dropping a column rebuilds `course` on SQLite, and batch mode cannot see an expression
|
|
27
|
+
# index: `ux_course_code` is dropped first and made again after, as 0016 does.
|
|
28
|
+
op.drop_index("ux_course_code", table_name="course")
|
|
29
|
+
with op.batch_alter_table("course") as batch_op:
|
|
30
|
+
batch_op.drop_column("dropped_at")
|
|
31
|
+
op.create_index(
|
|
32
|
+
"ux_course_code",
|
|
33
|
+
"course",
|
|
34
|
+
[sa.text("user_id"), sa.text("lower(code)"), sa.text("lower(semester_name)")],
|
|
35
|
+
unique=True,
|
|
36
|
+
)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""a course can declare it has no past papers, and a topic can come from its syllabus (D-218,
|
|
2
|
+
D-223, D-224)
|
|
3
|
+
|
|
4
|
+
Revision ID: 0018
|
|
5
|
+
Revises: 0017
|
|
6
|
+
Create Date: 2026-11-01
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import sqlalchemy as sa
|
|
10
|
+
from alembic import op
|
|
11
|
+
|
|
12
|
+
revision = "0018"
|
|
13
|
+
down_revision = "0017"
|
|
14
|
+
branch_labels = None
|
|
15
|
+
depends_on = None
|
|
16
|
+
|
|
17
|
+
OLD = "proposed_by IN ('material', 'profile', 'split')"
|
|
18
|
+
NEW = "proposed_by IN ('material', 'profile', 'split', 'syllabus')"
|
|
19
|
+
LIVE = "status IN ('proposed', 'active', 'unexamined')"
|
|
20
|
+
|
|
21
|
+
# Both tables are rebuilt on SQLite, and batch mode cannot see an expression index: `course`'s
|
|
22
|
+
# `ux_course_code` and `topic`'s partial `ux_topic_live` are dropped first and made again after,
|
|
23
|
+
# as 0016 does. `topic` is a parent table; env.py runs the rebuild with foreign keys off and
|
|
24
|
+
# checks them once before COMMIT (D-103). `no_past_papers` backfills to 0: no course had said so.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _course_code_index() -> None:
|
|
28
|
+
op.create_index(
|
|
29
|
+
"ux_course_code",
|
|
30
|
+
"course",
|
|
31
|
+
[sa.text("user_id"), sa.text("lower(code)"), sa.text("lower(semester_name)")],
|
|
32
|
+
unique=True,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _topic_live_index() -> None:
|
|
37
|
+
op.create_index(
|
|
38
|
+
"ux_topic_live",
|
|
39
|
+
"topic",
|
|
40
|
+
[sa.text("course_id"), sa.text("lower(name)")],
|
|
41
|
+
unique=True,
|
|
42
|
+
sqlite_where=sa.text(LIVE),
|
|
43
|
+
postgresql_where=sa.text(LIVE),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _set_sources(check: str) -> None:
|
|
48
|
+
"""Replace the `proposed_by` CHECK with `check`, under the same name."""
|
|
49
|
+
op.drop_index("ux_topic_live", table_name="topic")
|
|
50
|
+
with op.batch_alter_table("topic") as batch_op:
|
|
51
|
+
# op.f: the full name as written - the naming convention would prefix it a second time
|
|
52
|
+
batch_op.drop_constraint(op.f("ck_topic_proposed_by_enum"), type_="check")
|
|
53
|
+
batch_op.create_check_constraint(op.f("ck_topic_proposed_by_enum"), check)
|
|
54
|
+
_topic_live_index()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def upgrade() -> None:
|
|
58
|
+
op.drop_index("ux_course_code", table_name="course")
|
|
59
|
+
with op.batch_alter_table("course") as batch_op:
|
|
60
|
+
batch_op.add_column(
|
|
61
|
+
sa.Column(
|
|
62
|
+
"no_past_papers",
|
|
63
|
+
sa.Integer(),
|
|
64
|
+
sa.CheckConstraint(
|
|
65
|
+
"no_past_papers IN (0,1)", name=op.f("ck_course_no_past_papers_bool")
|
|
66
|
+
),
|
|
67
|
+
server_default=sa.text("0"),
|
|
68
|
+
nullable=False,
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
_course_code_index()
|
|
72
|
+
_set_sources(NEW)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def downgrade() -> None:
|
|
76
|
+
# Refused by the CHECK itself while a syllabus topic exists - v1 deletes no row (D-22).
|
|
77
|
+
_set_sources(OLD)
|
|
78
|
+
op.drop_index("ux_course_code", table_name="course")
|
|
79
|
+
with op.batch_alter_table("course") as batch_op:
|
|
80
|
+
batch_op.drop_constraint(op.f("ck_course_no_past_papers_bool"), type_="check")
|
|
81
|
+
batch_op.drop_column("no_past_papers")
|
|
82
|
+
_course_code_index()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""his lab group, per course - the week shows only that group's meetings (D-227)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0019
|
|
4
|
+
Revises: 0018
|
|
5
|
+
Create Date: 2026-11-01
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0019"
|
|
12
|
+
down_revision = "0018"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# A nullable column with no CHECK, as 0017: a plain ALTER TABLE ADD COLUMN on both engines, so
|
|
17
|
+
# `course` is not rebuilt and `ux_course_code` is never touched. No backfill: NULL = every group,
|
|
18
|
+
# which is what the week showed before this.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
op.add_column("course", sa.Column("lab_group", sa.Text(), nullable=True))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def downgrade() -> None:
|
|
26
|
+
# Dropping a column rebuilds `course` on SQLite, and batch mode cannot see an expression
|
|
27
|
+
# index: `ux_course_code` is dropped first and made again after, as 0017 does.
|
|
28
|
+
op.drop_index("ux_course_code", table_name="course")
|
|
29
|
+
with op.batch_alter_table("course") as batch_op:
|
|
30
|
+
batch_op.drop_column("lab_group")
|
|
31
|
+
op.create_index(
|
|
32
|
+
"ux_course_code",
|
|
33
|
+
"course",
|
|
34
|
+
[sa.text("user_id"), sa.text("lower(code)"), sa.text("lower(semester_name)")],
|
|
35
|
+
unique=True,
|
|
36
|
+
)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""minutes can go on a chapter, and a study item stores the chapter it shows under (D-238, D-240)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0020
|
|
4
|
+
Revises: 0019
|
|
5
|
+
Create Date: 2026-11-04
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0020"
|
|
12
|
+
down_revision = "0019"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
OLD_SCOPE = "NOT (topic_id IS NOT NULL AND setup_key IS NOT NULL)"
|
|
17
|
+
NEW_SCOPE = (
|
|
18
|
+
"CASE WHEN topic_id IS NULL THEN 0 ELSE 1 END"
|
|
19
|
+
" + CASE WHEN setup_key IS NULL THEN 0 ELSE 1 END"
|
|
20
|
+
" + CASE WHEN material_id IS NULL THEN 0 ELSE 1 END <= 1"
|
|
21
|
+
)
|
|
22
|
+
SCOPE_CHECK = "ck_hours_entry_one_scope" # full names, passed through op.f() below
|
|
23
|
+
CHAPTER_CHECK = "ck_plan_item_chapter_study_only"
|
|
24
|
+
HOURS_FK = "fk_hours_entry_material_id"
|
|
25
|
+
ITEM_FK = "fk_plan_item_material_id"
|
|
26
|
+
|
|
27
|
+
# Both tables are batch rebuilds, as in 0008 and 0014: SQLite adds a CHECK or a foreign key only
|
|
28
|
+
# by rebuilding the table. env.py runs them with foreign keys off (D-103). No backfill: existing
|
|
29
|
+
# hours keep their scopes, and the study items already stored stay NULL until a new plan (D-240).
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def upgrade() -> None:
|
|
33
|
+
with op.batch_alter_table("hours_entry") as batch_op:
|
|
34
|
+
batch_op.add_column(sa.Column("material_id", sa.Text(), nullable=True))
|
|
35
|
+
batch_op.create_foreign_key(
|
|
36
|
+
op.f(HOURS_FK), "material", ["material_id"], ["id"], ondelete="RESTRICT"
|
|
37
|
+
)
|
|
38
|
+
batch_op.drop_constraint(op.f(SCOPE_CHECK), type_="check")
|
|
39
|
+
batch_op.create_check_constraint(op.f(SCOPE_CHECK), NEW_SCOPE)
|
|
40
|
+
with op.batch_alter_table("plan_item") as batch_op:
|
|
41
|
+
batch_op.add_column(sa.Column("material_id", sa.Text(), nullable=True))
|
|
42
|
+
batch_op.create_foreign_key(
|
|
43
|
+
op.f(ITEM_FK), "material", ["material_id"], ["id"], ondelete="RESTRICT"
|
|
44
|
+
)
|
|
45
|
+
batch_op.create_check_constraint(
|
|
46
|
+
op.f(CHAPTER_CHECK), "NOT (material_id IS NOT NULL) OR (lane = 'study')"
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def downgrade() -> None:
|
|
51
|
+
# A chapter's minutes lose their chapter and stay as course-level hours, which a downgrade
|
|
52
|
+
# accepts: the old CHECK allows that, and no minute is lost.
|
|
53
|
+
with op.batch_alter_table("plan_item") as batch_op:
|
|
54
|
+
batch_op.drop_constraint(op.f(CHAPTER_CHECK), type_="check")
|
|
55
|
+
batch_op.drop_constraint(op.f(ITEM_FK), type_="foreignkey")
|
|
56
|
+
batch_op.drop_column("material_id")
|
|
57
|
+
with op.batch_alter_table("hours_entry") as batch_op:
|
|
58
|
+
batch_op.drop_constraint(op.f(SCOPE_CHECK), type_="check")
|
|
59
|
+
batch_op.drop_constraint(op.f(HOURS_FK), type_="foreignkey")
|
|
60
|
+
batch_op.drop_column("material_id")
|
|
61
|
+
batch_op.create_check_constraint(op.f(SCOPE_CHECK), OLD_SCOPE)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""a note can retire when its chapter's note is redone (D-250)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0021
|
|
4
|
+
Revises: 0020
|
|
5
|
+
Create Date: 2026-11-05
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0021"
|
|
12
|
+
down_revision = "0020"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# No backfill: every existing note is live, so NULL is right for all of them.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def upgrade() -> None:
|
|
20
|
+
with op.batch_alter_table("note") as batch_op:
|
|
21
|
+
batch_op.add_column(sa.Column("retired_at", sa.Text(), nullable=True))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def downgrade() -> None:
|
|
25
|
+
# A retired note comes back as live beside its replacement, which a downgrade accepts: no
|
|
26
|
+
# note text is lost, and the summary task then reads both.
|
|
27
|
+
with op.batch_alter_table("note") as batch_op:
|
|
28
|
+
batch_op.drop_column("retired_at")
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""a rescope retires an exam edge and frees a paper's positions (D-261, D-264)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0022
|
|
4
|
+
Revises: 0021
|
|
5
|
+
Create Date: 2026-11-10
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0022"
|
|
12
|
+
down_revision = "0021"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# No backfill: no edge has been retired and no item superseded yet, so NULL is right for every
|
|
17
|
+
# edge and the narrower index holds every row the old one held.
|
|
18
|
+
|
|
19
|
+
OLD_WHERE = "past_exam_id IS NOT NULL"
|
|
20
|
+
NEW_WHERE = "past_exam_id IS NOT NULL AND state <> 'superseded'"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _position_index(batch_op, where: str) -> None:
|
|
24
|
+
batch_op.create_index(
|
|
25
|
+
"ux_practice_item_position",
|
|
26
|
+
["past_exam_id", "position"],
|
|
27
|
+
unique=True,
|
|
28
|
+
sqlite_where=sa.text(where),
|
|
29
|
+
postgresql_where=sa.text(where),
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def upgrade() -> None:
|
|
34
|
+
with op.batch_alter_table("coverage") as batch_op:
|
|
35
|
+
batch_op.add_column(sa.Column("retired_at", sa.Text(), nullable=True))
|
|
36
|
+
with op.batch_alter_table("practice_item") as batch_op:
|
|
37
|
+
batch_op.drop_index("ux_practice_item_position")
|
|
38
|
+
_position_index(batch_op, NEW_WHERE)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def downgrade() -> None:
|
|
42
|
+
# A retired edge comes back as live. The old index fails to build once a redo has written a
|
|
43
|
+
# position its superseded item still holds - the downgrade then stops, and nothing changes.
|
|
44
|
+
with op.batch_alter_table("practice_item") as batch_op:
|
|
45
|
+
batch_op.drop_index("ux_practice_item_position")
|
|
46
|
+
_position_index(batch_op, OLD_WHERE)
|
|
47
|
+
with op.batch_alter_table("coverage") as batch_op:
|
|
48
|
+
batch_op.drop_column("retired_at")
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""an off-plan hour can give `backlog` as its reason (D-274)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0023
|
|
4
|
+
Revises: 0022
|
|
5
|
+
Create Date: 2026-11-13
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
revision = "0023"
|
|
11
|
+
down_revision = "0022"
|
|
12
|
+
branch_labels = None
|
|
13
|
+
depends_on = None
|
|
14
|
+
|
|
15
|
+
OLD = (
|
|
16
|
+
"deviation_reason IN ('external-deadline', 'disagreed', 'too-tired', 'topic-wrong',"
|
|
17
|
+
" 'unexplained')"
|
|
18
|
+
)
|
|
19
|
+
NEW = (
|
|
20
|
+
"deviation_reason IN ('external-deadline', 'disagreed', 'too-tired', 'topic-wrong',"
|
|
21
|
+
" 'backlog', 'unexplained')"
|
|
22
|
+
)
|
|
23
|
+
REASON_CHECK = "ck_hours_entry_deviation_reason_enum" # the full name, passed through op.f()
|
|
24
|
+
|
|
25
|
+
# A batch rebuild, as in 0011 and 0020: SQLite changes a CHECK only by rebuilding the table.
|
|
26
|
+
# env.py runs it with foreign keys off (D-103). No backfill: no live hour carries a reason yet.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _set_reasons(check: str) -> None:
|
|
30
|
+
"""Replace the `deviation_reason` CHECK with `check`, under the same name."""
|
|
31
|
+
with op.batch_alter_table("hours_entry") as batch_op:
|
|
32
|
+
batch_op.drop_constraint(op.f(REASON_CHECK), type_="check")
|
|
33
|
+
batch_op.create_check_constraint(op.f(REASON_CHECK), check)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def upgrade() -> None:
|
|
37
|
+
_set_reasons(NEW)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def downgrade() -> None:
|
|
41
|
+
# Refused by the CHECK itself while a `backlog` hour exists - v1 deletes no row (D-22).
|
|
42
|
+
_set_reasons(OLD)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""a plan stores how many shown study topics its guesses decide (D-281)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0024
|
|
4
|
+
Revises: 0023
|
|
5
|
+
Create Date: 2026-11-14
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0024"
|
|
12
|
+
down_revision = "0023"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# A batch add, as in 0015, so the column's CHECK lands on SQLite. Nullable and no backfill: an
|
|
17
|
+
# earlier plan never ran the side ranking, and NULL reads unknown, never 0 (D-281).
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def upgrade() -> None:
|
|
21
|
+
with op.batch_alter_table("plan") as batch_op:
|
|
22
|
+
batch_op.add_column(
|
|
23
|
+
sa.Column(
|
|
24
|
+
"guess_changed",
|
|
25
|
+
sa.Integer(),
|
|
26
|
+
sa.CheckConstraint("guess_changed >= 0", name=op.f("ck_plan_guess_changed_min")),
|
|
27
|
+
nullable=True,
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def downgrade() -> None:
|
|
33
|
+
with op.batch_alter_table("plan") as batch_op:
|
|
34
|
+
batch_op.drop_constraint(op.f("ck_plan_guess_changed_min"), type_="check")
|
|
35
|
+
batch_op.drop_column("guess_changed")
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""a course can declare its own hours per credit, and that it is an elective (D-294, D-300)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0025
|
|
4
|
+
Revises: 0024
|
|
5
|
+
Create Date: 2026-11-15
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0025"
|
|
12
|
+
down_revision = "0024"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# `course` is rebuilt on SQLite, and batch mode cannot see an expression index: `ux_course_code`
|
|
17
|
+
# is dropped first and made again after, as 0018 does. No backfill: every course starts with
|
|
18
|
+
# hours_per_credit NULL / `unknown` (the detector reads the default H, D-294) and elective 0.
|
|
19
|
+
|
|
20
|
+
TIER_RULE = (
|
|
21
|
+
"((hours_per_credit_tier = 'unknown') AND (hours_per_credit is NULL)) OR "
|
|
22
|
+
"(NOT (hours_per_credit_tier = 'unknown') AND NOT(hours_per_credit is NULL))"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _course_code_index() -> None:
|
|
27
|
+
op.create_index(
|
|
28
|
+
"ux_course_code",
|
|
29
|
+
"course",
|
|
30
|
+
[sa.text("user_id"), sa.text("lower(code)"), sa.text("lower(semester_name)")],
|
|
31
|
+
unique=True,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def upgrade() -> None:
|
|
36
|
+
op.drop_index("ux_course_code", table_name="course")
|
|
37
|
+
with op.batch_alter_table("course") as batch_op:
|
|
38
|
+
batch_op.add_column(
|
|
39
|
+
sa.Column(
|
|
40
|
+
"hours_per_credit",
|
|
41
|
+
sa.Float(),
|
|
42
|
+
sa.CheckConstraint(
|
|
43
|
+
"hours_per_credit > 0", name=op.f("ck_course_hours_per_credit_range")
|
|
44
|
+
),
|
|
45
|
+
nullable=True,
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
batch_op.add_column(
|
|
49
|
+
sa.Column(
|
|
50
|
+
"hours_per_credit_tier",
|
|
51
|
+
sa.Text(),
|
|
52
|
+
sa.CheckConstraint(
|
|
53
|
+
"hours_per_credit_tier IN ('declared', 'inferred', 'unknown')",
|
|
54
|
+
name=op.f("ck_course_hours_per_credit_tier_enum"),
|
|
55
|
+
),
|
|
56
|
+
server_default=sa.text("'unknown'"),
|
|
57
|
+
nullable=False,
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
batch_op.create_check_constraint(op.f("ck_course_hours_per_credit_tier_rule"), TIER_RULE)
|
|
61
|
+
batch_op.add_column(
|
|
62
|
+
sa.Column(
|
|
63
|
+
"elective",
|
|
64
|
+
sa.Integer(),
|
|
65
|
+
sa.CheckConstraint("elective IN (0,1)", name=op.f("ck_course_elective_bool")),
|
|
66
|
+
server_default=sa.text("0"),
|
|
67
|
+
nullable=False,
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
_course_code_index()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def downgrade() -> None:
|
|
74
|
+
op.drop_index("ux_course_code", table_name="course")
|
|
75
|
+
with op.batch_alter_table("course") as batch_op:
|
|
76
|
+
batch_op.drop_constraint(op.f("ck_course_elective_bool"), type_="check")
|
|
77
|
+
batch_op.drop_column("elective")
|
|
78
|
+
batch_op.drop_constraint(op.f("ck_course_hours_per_credit_tier_rule"), type_="check")
|
|
79
|
+
batch_op.drop_constraint(op.f("ck_course_hours_per_credit_tier_enum"), type_="check")
|
|
80
|
+
batch_op.drop_constraint(op.f("ck_course_hours_per_credit_range"), type_="check")
|
|
81
|
+
batch_op.drop_column("hours_per_credit_tier")
|
|
82
|
+
batch_op.drop_column("hours_per_credit")
|
|
83
|
+
_course_code_index()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""a student turns discrimination trials on; off by default (D-312, D-313)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0026
|
|
4
|
+
Revises: 0025
|
|
5
|
+
Create Date: 2026-11-19
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0026"
|
|
12
|
+
down_revision = "0025"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# `user` is rebuilt on SQLite (batch mode). No backfill: the server default gives every existing
|
|
17
|
+
# user 0, trials off - the D-312 default.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def upgrade() -> None:
|
|
21
|
+
with op.batch_alter_table("user") as batch_op:
|
|
22
|
+
batch_op.add_column(
|
|
23
|
+
sa.Column(
|
|
24
|
+
"trials_on",
|
|
25
|
+
sa.Integer(),
|
|
26
|
+
sa.CheckConstraint("trials_on IN (0,1)", name=op.f("ck_user_trials_on_bool")),
|
|
27
|
+
server_default=sa.text("0"),
|
|
28
|
+
nullable=False,
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def downgrade() -> None:
|
|
34
|
+
with op.batch_alter_table("user") as batch_op:
|
|
35
|
+
batch_op.drop_constraint(op.f("ck_user_trials_on_bool"), type_="check")
|
|
36
|
+
batch_op.drop_column("trials_on")
|