Thirteen plans were seeded with an API to serve them and nothing that called it, so the whole feature existed only in the database. Two pages and the editing endpoints it was missing. /study-plans lists the plans with progress stated in blocks — "3 of 6 blocks" is something you can act on, where "50%" only tells you how you feel about it. /study-plans/:id is one plan: each block shows Articles, then Sessions, in that order, because that is the order the block is meant to be done in. Reading is now part of a block (migration f4a5b6c7d8e9). "Mark as read" is the learner's own claim and reversible — someone who ticks the wrong row should be able to fix it without an educator, and progress nobody can correct stops being trusted and then stops being used. It is a separate table from `article_views` on purpose: opening an article is not the same claim as having finished with it. A draft article attached to a block is listed for the educator who can open it and left out for everyone else, rather than offered as a dead link. Editing is inline on the learner's own page rather than a separate builder, so the thing being changed and the thing a learner sees are the same object. Moderators create (as a draft — an empty plan is not something to put in front of anyone), rename, publish, delete; add, rename, reorder and remove blocks; move questions between blocks of one plan; attach reading found by searching rather than by id. Two places where the obvious implementation leaves the data wrong, both tested: deleting a block out of the middle shuffles the survivors down, or the next insert collides with a position nothing occupies; and reordering parks every row outside the range before writing the real positions, because (plan_id, position) is unique and the first move would otherwise collide with a position still held. A partial order is refused rather than half-applied. 166 backend, 188 frontend green. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XeFQJXJTfHKTfbfsdxv57Z
42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
"""Reading attached to a study plan block, and who has finished it.
|
|
|
|
Revision ID: f4a5b6c7d8e9
|
|
Revises: e3f4a5b6c7d8
|
|
"""
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision = "f4a5b6c7d8e9"
|
|
down_revision = "e3f4a5b6c7d8"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
op.create_table(
|
|
"study_plan_block_articles",
|
|
sa.Column("id", sa.Integer, primary_key=True),
|
|
sa.Column("block_id", sa.Integer,
|
|
sa.ForeignKey("study_plan_blocks.id", ondelete="CASCADE"), nullable=False, index=True),
|
|
sa.Column("article_id", sa.Integer,
|
|
sa.ForeignKey("articles.id", ondelete="CASCADE"), nullable=False, index=True),
|
|
sa.Column("position", sa.Integer, server_default="0"),
|
|
sa.UniqueConstraint("block_id", "article_id", name="uq_block_article"),
|
|
)
|
|
# Opening an article is not the same claim as having finished with it, so
|
|
# this is its own table rather than a flag on article_views.
|
|
op.create_table(
|
|
"study_plan_article_reads",
|
|
sa.Column("id", sa.Integer, primary_key=True),
|
|
sa.Column("block_article_id", sa.Integer,
|
|
sa.ForeignKey("study_plan_block_articles.id", ondelete="CASCADE"), nullable=False, index=True),
|
|
sa.Column("user_id", sa.Integer,
|
|
sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True),
|
|
sa.Column("read_at", sa.DateTime, server_default=sa.func.now()),
|
|
sa.UniqueConstraint("block_article_id", "user_id", name="uq_block_article_read"),
|
|
)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_table("study_plan_article_reads")
|
|
op.drop_table("study_plan_block_articles")
|