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,38 @@
|
|
|
1
|
+
"""a course's semester is unique ignoring case, like its code (D-40)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0002
|
|
4
|
+
Revises: 0001
|
|
5
|
+
Create Date: 2026-09-26
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0002"
|
|
12
|
+
down_revision = "0001"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# An index is dropped and rebuilt on its own - the table is not rebuilt, so batch mode and
|
|
17
|
+
# `foreign_keys = ON` never meet here. Written by hand for the reason 0001 gives: autogenerate
|
|
18
|
+
# cannot see an expression index.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
op.drop_index("ux_course_code", table_name="course")
|
|
23
|
+
op.create_index(
|
|
24
|
+
"ux_course_code",
|
|
25
|
+
"course",
|
|
26
|
+
[sa.text("user_id"), sa.text("lower(code)"), sa.text("lower(semester_name)")],
|
|
27
|
+
unique=True,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def downgrade() -> None:
|
|
32
|
+
op.drop_index("ux_course_code", table_name="course")
|
|
33
|
+
op.create_index(
|
|
34
|
+
"ux_course_code",
|
|
35
|
+
"course",
|
|
36
|
+
[sa.text("user_id"), sa.text("lower(code)"), sa.text("semester_name")],
|
|
37
|
+
unique=True,
|
|
38
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""a course names its folder in the vault, for the note export (D-72)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0003
|
|
4
|
+
Revises: 0002
|
|
5
|
+
Create Date: 2026-10-01
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0003"
|
|
12
|
+
down_revision = "0002"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# Plain ADD / DROP COLUMN, not batch mode: both engines alter the column in place (SQLite since
|
|
17
|
+
# 3.35), so the table is never rebuilt and batch mode never meets `foreign_keys = ON` (env.py).
|
|
18
|
+
# A nullable column with no default needs no backfill: every course starts undeclared.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
op.add_column("course", sa.Column("vault_folder", sa.Text(), nullable=True))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def downgrade() -> None:
|
|
26
|
+
op.drop_column("course", "vault_folder")
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""a note records where its PDF went, beside its markdown (D-81)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0004
|
|
4
|
+
Revises: 0003
|
|
5
|
+
Create Date: 2026-10-04
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0004"
|
|
12
|
+
down_revision = "0003"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# Plain ADD / DROP COLUMN, as in 0003: no table rebuild on either engine. Nullable with no
|
|
17
|
+
# default, so no backfill: every existing note starts with its PDF not written - Chapter 6's
|
|
18
|
+
# included, which study_export_notes then writes (D-79).
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
op.add_column("note", sa.Column("pdf_path", sa.Text(), nullable=True))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def downgrade() -> None:
|
|
26
|
+
op.drop_column("note", "pdf_path")
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""a generation task can be a tagging - a chapter linked to the topics it teaches (D-93)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0005
|
|
4
|
+
Revises: 0004
|
|
5
|
+
Create Date: 2026-10-05
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
revision = "0005"
|
|
11
|
+
down_revision = "0004"
|
|
12
|
+
branch_labels = None
|
|
13
|
+
depends_on = None
|
|
14
|
+
|
|
15
|
+
OLD = "kind IN ('note', 'practice', 'memory', 'transcription', 'timetable')"
|
|
16
|
+
NEW = "kind IN ('note', 'practice', 'memory', 'transcription', 'timetable', 'tagging')"
|
|
17
|
+
|
|
18
|
+
# The first migration that rebuilds a parent table: SQLite changes a CHECK only by rebuilding
|
|
19
|
+
# the table, and `submission`, `note` and `practice_item` point at `generation_task`. env.py
|
|
20
|
+
# runs it with foreign keys off and checks them once before COMMIT (D-103). Postgres alters the
|
|
21
|
+
# CHECK in place.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _set_kinds(check: str) -> None:
|
|
25
|
+
"""Replace the `kind` CHECK with `check`, under the same name."""
|
|
26
|
+
with op.batch_alter_table("generation_task") as batch_op:
|
|
27
|
+
# op.f: the full name as written - the metadata's naming convention reaches batch mode
|
|
28
|
+
# and would prefix it a second time
|
|
29
|
+
batch_op.drop_constraint(op.f("ck_generation_task_kind_enum"), type_="check")
|
|
30
|
+
batch_op.create_check_constraint(op.f("ck_generation_task_kind_enum"), check)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def upgrade() -> None:
|
|
34
|
+
_set_kinds(NEW)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def downgrade() -> None:
|
|
38
|
+
# Refused by the CHECK itself while a tagging task exists - v1 deletes no row (D-22).
|
|
39
|
+
_set_kinds(OLD)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""a study session can be practice - past-exam questions on one topic, solved alone (1.16)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0006
|
|
4
|
+
Revises: 0005
|
|
5
|
+
Create Date: 2026-10-07
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
revision = "0006"
|
|
11
|
+
down_revision = "0005"
|
|
12
|
+
branch_labels = None
|
|
13
|
+
depends_on = None
|
|
14
|
+
|
|
15
|
+
OLD = "mode IN ('explain-chapter', 'exam-walkthrough', 'mock', 'review-quiz')"
|
|
16
|
+
NEW = "mode IN ('explain-chapter', 'exam-walkthrough', 'mock', 'review-quiz', 'practice')"
|
|
17
|
+
|
|
18
|
+
# `attempt` and `hours_entry` point at `study_session`, so on SQLite this is a parent rebuild
|
|
19
|
+
# like 0005 - env.py runs it with foreign keys off (D-103). Postgres alters the CHECK in place.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _set_modes(check: str) -> None:
|
|
23
|
+
"""Replace the `mode` CHECK with `check`, under the same name."""
|
|
24
|
+
with op.batch_alter_table("study_session") as batch_op:
|
|
25
|
+
# op.f: the full name as written - the naming convention would prefix it a second time
|
|
26
|
+
batch_op.drop_constraint(op.f("ck_study_session_mode_enum"), type_="check")
|
|
27
|
+
batch_op.create_check_constraint(op.f("ck_study_session_mode_enum"), check)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def upgrade() -> None:
|
|
31
|
+
_set_modes(NEW)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def downgrade() -> None:
|
|
35
|
+
# Refused by the CHECK itself while a practice session exists - v1 deletes no row (D-22).
|
|
36
|
+
_set_modes(OLD)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""an exam records the day its prep starts - from then the plan reads its topics by marks (D-119)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0007
|
|
4
|
+
Revises: 0006
|
|
5
|
+
Create Date: 2026-10-09
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0007"
|
|
12
|
+
down_revision = "0006"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# Plain ADD / DROP COLUMN, as in 0003 and 0004: no table rebuild on either engine. Nullable with
|
|
17
|
+
# no default, so no backfill: every existing exam starts in term mode until he declares its prep.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def upgrade() -> None:
|
|
21
|
+
op.add_column("assessment", sa.Column("prep_from", sa.Text(), nullable=True))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def downgrade() -> None:
|
|
25
|
+
op.drop_column("assessment", "prep_from")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""a setup item can ask for more papers because a topic is short of questions (1.18, D-128)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0008
|
|
4
|
+
Revises: 0007
|
|
5
|
+
Create Date: 2026-10-10
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
revision = "0008"
|
|
11
|
+
down_revision = "0007"
|
|
12
|
+
branch_labels = None
|
|
13
|
+
depends_on = None
|
|
14
|
+
|
|
15
|
+
KINDS = "'grading', 'credits', 'exam-date', 'target-grade', 'first-material', 'past-papers'"
|
|
16
|
+
OLD = f"setup_kind IN ({KINDS})"
|
|
17
|
+
NEW = f"setup_kind IN ({KINDS}, 'more-papers')"
|
|
18
|
+
|
|
19
|
+
# No table points at `plan_item`, so on SQLite this is a plain rebuild of one table, as in 0006.
|
|
20
|
+
# Postgres alters the CHECK in place.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _set_kinds(check: str) -> None:
|
|
24
|
+
"""Replace the `setup_kind` CHECK with `check`, under the same name."""
|
|
25
|
+
with op.batch_alter_table("plan_item") as batch_op:
|
|
26
|
+
# op.f: the full name as written - the naming convention would prefix it a second time
|
|
27
|
+
batch_op.drop_constraint(op.f("ck_plan_item_setup_kind_enum"), type_="check")
|
|
28
|
+
batch_op.create_check_constraint(op.f("ck_plan_item_setup_kind_enum"), check)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def upgrade() -> None:
|
|
32
|
+
_set_kinds(NEW)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def downgrade() -> None:
|
|
36
|
+
# Refused by the CHECK itself while a more-papers item exists - v1 deletes no row (D-22).
|
|
37
|
+
_set_kinds(OLD)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""a past paper that prints only its month is dated the 1st, marked approximate (D-137)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0009
|
|
4
|
+
Revises: 0008
|
|
5
|
+
Create Date: 2026-10-10
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
revision = "0009"
|
|
11
|
+
down_revision = "0008"
|
|
12
|
+
branch_labels = None
|
|
13
|
+
depends_on = None
|
|
14
|
+
|
|
15
|
+
# Plain ADD / DROP COLUMN, as in 0003 and 0007: no table rebuild on either engine. Written as SQL
|
|
16
|
+
# because the column carries its named CHECK inline, which both engines accept on ADD COLUMN.
|
|
17
|
+
# NOT NULL DEFAULT 0 backfills every existing paper as exact - each one printed its day (D-43).
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def upgrade() -> None:
|
|
21
|
+
op.execute(
|
|
22
|
+
"ALTER TABLE past_exam ADD COLUMN session_date_approx INTEGER DEFAULT 0 NOT NULL "
|
|
23
|
+
"CONSTRAINT ck_past_exam_session_date_approx_bool CHECK (session_date_approx IN (0,1))"
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def downgrade() -> None:
|
|
28
|
+
op.drop_column("past_exam", "session_date_approx")
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""a generation task too big for one reply goes out in parts, fetched in order (D-145)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0010
|
|
4
|
+
Revises: 0009
|
|
5
|
+
Create Date: 2026-10-12
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0010"
|
|
12
|
+
down_revision = "0009"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# A batch rebuild, as in 0005: `parts_sent <= parts` is a table CHECK across two columns, which
|
|
17
|
+
# SQLite adds only by rebuilding the table. env.py runs it with foreign keys off (D-103).
|
|
18
|
+
# Backfill: every task so far went out as one reply, so `parts` is 1. A closed task got it
|
|
19
|
+
# (`parts_sent` 1); an open one counts as never fetched (0), so its submit waits for a fetch
|
|
20
|
+
# under the new rule - the only open task, I3304's tagging, never arrived whole anyway.
|
|
21
|
+
# `layout_hash` stays NULL: the content those replies were cut from was never hashed.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def upgrade() -> None:
|
|
25
|
+
with op.batch_alter_table("generation_task") as batch_op:
|
|
26
|
+
batch_op.add_column(
|
|
27
|
+
sa.Column(
|
|
28
|
+
"parts",
|
|
29
|
+
sa.Integer(),
|
|
30
|
+
sa.CheckConstraint("parts >= 1", name=op.f("ck_generation_task_parts_min")),
|
|
31
|
+
server_default=sa.text("1"),
|
|
32
|
+
nullable=False,
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
batch_op.add_column(
|
|
36
|
+
sa.Column(
|
|
37
|
+
"parts_sent",
|
|
38
|
+
sa.Integer(),
|
|
39
|
+
sa.CheckConstraint(
|
|
40
|
+
"parts_sent >= 0", name=op.f("ck_generation_task_parts_sent_min")
|
|
41
|
+
),
|
|
42
|
+
server_default=sa.text("0"),
|
|
43
|
+
nullable=False,
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
batch_op.add_column(
|
|
47
|
+
sa.Column(
|
|
48
|
+
"layout_hash",
|
|
49
|
+
sa.Text(),
|
|
50
|
+
sa.CheckConstraint(
|
|
51
|
+
"length(layout_hash) = 64", name=op.f("ck_generation_task_layout_hash_len")
|
|
52
|
+
),
|
|
53
|
+
nullable=True,
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
batch_op.create_check_constraint(
|
|
57
|
+
op.f("ck_generation_task_parts_sent_max"), "parts_sent <= parts"
|
|
58
|
+
)
|
|
59
|
+
op.execute("UPDATE generation_task SET parts_sent = 1 WHERE status <> 'open'")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def downgrade() -> None:
|
|
63
|
+
# Each CHECK goes by name before its column: batch mode reflects them as table CHECKs, and
|
|
64
|
+
# one left behind names a column the rebuilt table no longer has.
|
|
65
|
+
with op.batch_alter_table("generation_task") as batch_op:
|
|
66
|
+
for name in ("parts_sent_max", "layout_hash_len", "parts_sent_min", "parts_min"):
|
|
67
|
+
batch_op.drop_constraint(op.f(f"ck_generation_task_{name}"), type_="check")
|
|
68
|
+
batch_op.drop_column("layout_hash")
|
|
69
|
+
batch_op.drop_column("parts_sent")
|
|
70
|
+
batch_op.drop_column("parts")
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""a generation task can be an observation - one paper's format and instructor claims (D-149)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0011
|
|
4
|
+
Revises: 0010
|
|
5
|
+
Create Date: 2026-10-13
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
revision = "0011"
|
|
11
|
+
down_revision = "0010"
|
|
12
|
+
branch_labels = None
|
|
13
|
+
depends_on = None
|
|
14
|
+
|
|
15
|
+
OLD = "kind IN ('note', 'practice', 'memory', 'transcription', 'timetable', 'tagging')"
|
|
16
|
+
NEW = (
|
|
17
|
+
"kind IN ('note', 'practice', 'memory', 'transcription', 'timetable', 'tagging', 'observation')"
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
# A batch rebuild of a parent table, as in 0005: SQLite changes a CHECK only by rebuilding the
|
|
21
|
+
# table. env.py runs it with foreign keys off and checks them once before COMMIT (D-103).
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _set_kinds(check: str) -> None:
|
|
25
|
+
"""Replace the `kind` CHECK with `check`, under the same name."""
|
|
26
|
+
with op.batch_alter_table("generation_task") as batch_op:
|
|
27
|
+
# op.f: the full name as written - the metadata's naming convention reaches batch mode
|
|
28
|
+
# and would prefix it a second time
|
|
29
|
+
batch_op.drop_constraint(op.f("ck_generation_task_kind_enum"), type_="check")
|
|
30
|
+
batch_op.create_check_constraint(op.f("ck_generation_task_kind_enum"), check)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def upgrade() -> None:
|
|
34
|
+
_set_kinds(NEW)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def downgrade() -> None:
|
|
38
|
+
# Refused by the CHECK itself while an observation task exists - v1 deletes no row (D-22).
|
|
39
|
+
_set_kinds(OLD)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""a profile version records the observations it kept, one `profile_claim` row each (D-156)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0012
|
|
4
|
+
Revises: 0011
|
|
5
|
+
Create Date: 2026-10-14
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0012"
|
|
12
|
+
down_revision = "0011"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# A new table only - no rebuild, so no batch mode. No owner column, as `topic_weight`: its owner
|
|
17
|
+
# is reached through both FKs (physical-schema.md, "Ownership").
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def upgrade() -> None:
|
|
21
|
+
op.create_table(
|
|
22
|
+
"profile_claim",
|
|
23
|
+
sa.Column("id", sa.Text(), nullable=False),
|
|
24
|
+
sa.Column("exam_profile_id", sa.Text(), nullable=False),
|
|
25
|
+
sa.Column("observation_id", sa.Text(), nullable=False),
|
|
26
|
+
sa.Column("created_at", sa.Text(), nullable=False),
|
|
27
|
+
sa.CheckConstraint("length(id) = 26", name=op.f("ck_profile_claim_id_ulid")),
|
|
28
|
+
sa.ForeignKeyConstraint(
|
|
29
|
+
["exam_profile_id"],
|
|
30
|
+
["exam_profile.id"],
|
|
31
|
+
name=op.f("fk_profile_claim_exam_profile_id"),
|
|
32
|
+
ondelete="RESTRICT",
|
|
33
|
+
),
|
|
34
|
+
sa.ForeignKeyConstraint(
|
|
35
|
+
["observation_id"],
|
|
36
|
+
["observation.id"],
|
|
37
|
+
name=op.f("fk_profile_claim_observation_id"),
|
|
38
|
+
ondelete="RESTRICT",
|
|
39
|
+
),
|
|
40
|
+
sa.PrimaryKeyConstraint("id", name=op.f("pk_profile_claim")),
|
|
41
|
+
sa.UniqueConstraint(
|
|
42
|
+
"exam_profile_id",
|
|
43
|
+
"observation_id",
|
|
44
|
+
name=op.f("uq_profile_claim_exam_profile_id_observation_id"),
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def downgrade() -> None:
|
|
50
|
+
# The rows are derived (D-156): the next derive writes them again, so dropping them loses
|
|
51
|
+
# no input.
|
|
52
|
+
op.drop_table("profile_claim")
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""a profile counts the papers whose instructor it assumed (D-174, D-176)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0013
|
|
4
|
+
Revises: 0012
|
|
5
|
+
Create Date: 2026-10-16
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0013"
|
|
12
|
+
down_revision = "0012"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# A batch rebuild of a parent table, as in 0011: SQLite adds a CHECK only by rebuilding the
|
|
17
|
+
# table. env.py runs it with foreign keys off and checks them once before COMMIT (D-103).
|
|
18
|
+
# Every existing profile reads 0, which is true: before 2.4 derive assumed no instructor (D-150).
|
|
19
|
+
|
|
20
|
+
CHECK = "ck_exam_profile_count_assumed_min" # full name, passed through op.f() below
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def upgrade() -> None:
|
|
24
|
+
with op.batch_alter_table("exam_profile") as batch_op:
|
|
25
|
+
batch_op.add_column(
|
|
26
|
+
sa.Column(
|
|
27
|
+
"assumed_instructor_papers",
|
|
28
|
+
sa.Integer(),
|
|
29
|
+
server_default=sa.text("0"),
|
|
30
|
+
nullable=False,
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
batch_op.create_check_constraint(op.f(CHECK), "assumed_instructor_papers >= 0")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def downgrade() -> None:
|
|
37
|
+
# The count is derived: the next derive writes it again, so dropping it loses no input.
|
|
38
|
+
with op.batch_alter_table("exam_profile") as batch_op:
|
|
39
|
+
batch_op.drop_constraint(op.f(CHECK), type_="check")
|
|
40
|
+
batch_op.drop_column("assumed_instructor_papers")
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""a scan's transcription counts once confirmed, and each scanned item names its page (D-210)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0014
|
|
4
|
+
Revises: 0013
|
|
5
|
+
Create Date: 2026-10-20
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0014"
|
|
12
|
+
down_revision = "0013"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# `past_exam` gets a plain ADD / DROP COLUMN, as in 0009: a batch rebuild would turn its inline
|
|
17
|
+
# CHECKs into table ones, and 0009's own downgrade then cannot drop its column. `practice_item` is
|
|
18
|
+
# a batch rebuild, as in 0011 and 0013: SQLite adds a CHECK only by rebuilding the table. env.py
|
|
19
|
+
# runs it with foreign keys off and checks them once before COMMIT (D-103).
|
|
20
|
+
# Every paper already transcribed was a text-layer one and counted at submit, so it is stamped with
|
|
21
|
+
# its task's close time: derive (D-210) reads only stamped papers, and none may drop out.
|
|
22
|
+
|
|
23
|
+
PAGE_CHECK = "ck_practice_item_page_min" # full name, passed through op.f() below
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def upgrade() -> None:
|
|
27
|
+
op.add_column("past_exam", sa.Column("transcript_confirmed_at", sa.Text(), nullable=True))
|
|
28
|
+
op.execute(
|
|
29
|
+
"UPDATE past_exam SET transcript_confirmed_at = "
|
|
30
|
+
"(SELECT closed_at FROM generation_task WHERE generation_task.id = past_exam.transcript_task_id) "
|
|
31
|
+
"WHERE transcript_task_id IS NOT NULL"
|
|
32
|
+
)
|
|
33
|
+
with op.batch_alter_table("practice_item") as batch_op:
|
|
34
|
+
batch_op.add_column(sa.Column("page", sa.Integer(), nullable=True))
|
|
35
|
+
batch_op.create_check_constraint(op.f(PAGE_CHECK), "page >= 1")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def downgrade() -> None:
|
|
39
|
+
# Dropping the stamp loses no input: a typed paper is stamped again at submit. A scan's page
|
|
40
|
+
# and confirmation are lost, which a downgrade accepts.
|
|
41
|
+
with op.batch_alter_table("practice_item") as batch_op:
|
|
42
|
+
batch_op.drop_constraint(op.f(PAGE_CHECK), type_="check")
|
|
43
|
+
batch_op.drop_column("page")
|
|
44
|
+
op.drop_column("past_exam", "transcript_confirmed_at")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""a practice task remembers how many items the student asked for (D-211)
|
|
2
|
+
|
|
3
|
+
Revision ID: 0015
|
|
4
|
+
Revises: 0014
|
|
5
|
+
Create Date: 2026-10-22
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sqlalchemy as sa
|
|
9
|
+
from alembic import op
|
|
10
|
+
|
|
11
|
+
revision = "0015"
|
|
12
|
+
down_revision = "0014"
|
|
13
|
+
branch_labels = None
|
|
14
|
+
depends_on = None
|
|
15
|
+
|
|
16
|
+
# A batch add, as in 0010, so the column's CHECK lands on SQLite. Nullable and no backfill: every
|
|
17
|
+
# earlier task is a kind that asks for no count, and NULL means the host chooses.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def upgrade() -> None:
|
|
21
|
+
with op.batch_alter_table("generation_task") as batch_op:
|
|
22
|
+
batch_op.add_column(
|
|
23
|
+
sa.Column(
|
|
24
|
+
"item_count",
|
|
25
|
+
sa.Integer(),
|
|
26
|
+
sa.CheckConstraint(
|
|
27
|
+
"item_count >= 1", name=op.f("ck_generation_task_item_count_min")
|
|
28
|
+
),
|
|
29
|
+
nullable=True,
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def downgrade() -> None:
|
|
35
|
+
with op.batch_alter_table("generation_task") as batch_op:
|
|
36
|
+
batch_op.drop_constraint(op.f("ck_generation_task_item_count_min"), type_="check")
|
|
37
|
+
batch_op.drop_column("item_count")
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""a meeting can repeat in odd or even weeks or belong to one lab group, and a course can be
|
|
2
|
+
left out of the plan (D-216)
|
|
3
|
+
|
|
4
|
+
Revision ID: 0016
|
|
5
|
+
Revises: 0015
|
|
6
|
+
Create Date: 2026-10-31
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import sqlalchemy as sa
|
|
10
|
+
from alembic import op
|
|
11
|
+
|
|
12
|
+
revision = "0016"
|
|
13
|
+
down_revision = "0015"
|
|
14
|
+
branch_labels = None
|
|
15
|
+
depends_on = None
|
|
16
|
+
|
|
17
|
+
# `class_meeting`'s unique key becomes an expression index, because two NULL pattern columns
|
|
18
|
+
# would never collide in a plain key. Batch mode rebuilds a table on SQLite and its reflection
|
|
19
|
+
# cannot see an expression index, so `ux_course_code` is dropped before `course` is rebuilt and
|
|
20
|
+
# made again after (as 0002 made it). Every earlier meeting is a whole-class, every-week row, so
|
|
21
|
+
# no backfill is needed; `planned` backfills to 1.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _course_code_index() -> None:
|
|
25
|
+
op.create_index(
|
|
26
|
+
"ux_course_code",
|
|
27
|
+
"course",
|
|
28
|
+
[sa.text("user_id"), sa.text("lower(code)"), sa.text("lower(semester_name)")],
|
|
29
|
+
unique=True,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def upgrade() -> None:
|
|
34
|
+
with op.batch_alter_table("class_meeting") as batch_op:
|
|
35
|
+
batch_op.drop_constraint(
|
|
36
|
+
op.f("uq_class_meeting_course_id_weekday_start_time_kind"), type_="unique"
|
|
37
|
+
)
|
|
38
|
+
batch_op.add_column(
|
|
39
|
+
sa.Column(
|
|
40
|
+
"week_parity",
|
|
41
|
+
sa.Text(),
|
|
42
|
+
sa.CheckConstraint(
|
|
43
|
+
"week_parity IN ('odd', 'even')",
|
|
44
|
+
name=op.f("ck_class_meeting_week_parity_enum"),
|
|
45
|
+
),
|
|
46
|
+
nullable=True,
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
batch_op.add_column(
|
|
50
|
+
sa.Column(
|
|
51
|
+
"group_label",
|
|
52
|
+
sa.Text(),
|
|
53
|
+
sa.CheckConstraint(
|
|
54
|
+
"group_label IS NULL OR length(group_label) > 0",
|
|
55
|
+
name=op.f("ck_class_meeting_group_not_empty"),
|
|
56
|
+
),
|
|
57
|
+
nullable=True,
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
op.create_index(
|
|
61
|
+
"ux_class_meeting_slot",
|
|
62
|
+
"class_meeting",
|
|
63
|
+
[
|
|
64
|
+
sa.text("course_id"),
|
|
65
|
+
sa.text("weekday"),
|
|
66
|
+
sa.text("start_time"),
|
|
67
|
+
sa.text("kind"),
|
|
68
|
+
sa.text("coalesce(week_parity, '')"),
|
|
69
|
+
sa.text("coalesce(group_label, '')"),
|
|
70
|
+
],
|
|
71
|
+
unique=True,
|
|
72
|
+
)
|
|
73
|
+
op.drop_index("ux_course_code", table_name="course")
|
|
74
|
+
with op.batch_alter_table("course") as batch_op:
|
|
75
|
+
batch_op.add_column(
|
|
76
|
+
sa.Column(
|
|
77
|
+
"planned",
|
|
78
|
+
sa.Integer(),
|
|
79
|
+
sa.CheckConstraint("planned IN (0,1)", name=op.f("ck_course_planned_bool")),
|
|
80
|
+
server_default=sa.text("1"),
|
|
81
|
+
nullable=False,
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
_course_code_index()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def downgrade() -> None:
|
|
88
|
+
op.drop_index("ux_course_code", table_name="course")
|
|
89
|
+
with op.batch_alter_table("course") as batch_op:
|
|
90
|
+
batch_op.drop_constraint(op.f("ck_course_planned_bool"), type_="check")
|
|
91
|
+
batch_op.drop_column("planned")
|
|
92
|
+
_course_code_index()
|
|
93
|
+
op.drop_index("ux_class_meeting_slot", table_name="class_meeting")
|
|
94
|
+
with op.batch_alter_table("class_meeting") as batch_op:
|
|
95
|
+
batch_op.drop_constraint(op.f("ck_class_meeting_group_not_empty"), type_="check")
|
|
96
|
+
batch_op.drop_column("group_label")
|
|
97
|
+
batch_op.drop_constraint(op.f("ck_class_meeting_week_parity_enum"), type_="check")
|
|
98
|
+
batch_op.drop_column("week_parity")
|
|
99
|
+
batch_op.create_unique_constraint(
|
|
100
|
+
op.f("uq_class_meeting_course_id_weekday_start_time_kind"),
|
|
101
|
+
["course_id", "weekday", "start_time", "kind"],
|
|
102
|
+
)
|