-
Notifications
You must be signed in to change notification settings - Fork 27
[6/7] Record task status transitions #277
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
Open
alex-clickhouse
wants to merge
2
commits into
alex-clickhouse/task-detail-modal
from
alex-clickhouse/task-events
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """V44: status-transition history for tasks. | ||
|
|
||
| ``tasks`` stores only the current status, so every transition overwrote | ||
| the last one and nothing recorded that it happened. The markdown file's | ||
| ``## Updates`` section was the closest thing to a history, and it only | ||
| gains a line when a note is passed or on done/reopen — a plain status | ||
| flip left no trace at all, at day granularity and with no actor. | ||
|
|
||
| That was tolerable while status changes were rare and deliberate. The | ||
| task board makes them a drag, so they're frequent, and it raises the | ||
| questions this table answers: how long has this been in progress, which | ||
| cards are aging, how often does work bounce back out of review. | ||
|
|
||
| Rows are append-only. ``from_status`` is NULL for the row recording a | ||
| task's creation, so a task's first event is its birth rather than an | ||
| implicit gap before the first transition. | ||
|
|
||
| Timestamps are TEXT written Python-side as UTC ISO strings, matching every | ||
| other table here. They are not fixed width — ``isoformat()`` drops the | ||
| fractional part on an exact second — but lexicographic order is still | ||
| chronological, because the only characters that can follow the seconds | ||
| field are ``+`` (0x2B) and ``.`` (0x2E), and both sort below every digit. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
|
|
||
| import aiosqlite | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| SQL = """ | ||
| CREATE TABLE IF NOT EXISTS task_events ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| task_id TEXT NOT NULL, | ||
| from_status TEXT, | ||
| to_status TEXT NOT NULL, | ||
| actor TEXT NOT NULL DEFAULT 'system', | ||
| created_at TEXT NOT NULL | ||
| ); | ||
|
|
||
| -- The only read pattern: one task's history, oldest first. | ||
| CREATE INDEX IF NOT EXISTS idx_task_events_task | ||
| ON task_events(task_id, created_at); | ||
|
|
||
| -- Aging queries sweep by time across all tasks. | ||
| CREATE INDEX IF NOT EXISTS idx_task_events_created | ||
| ON task_events(created_at); | ||
| """ | ||
|
|
||
|
|
||
| async def up(db: aiosqlite.Connection) -> None: | ||
| await db.executescript(SQL) | ||
|
|
||
| # Seed one event per existing task so history has a floor rather than | ||
| # starting mid-air. created_at (not updated_at) is the honest stamp: | ||
| # we know when the task appeared, not when it reached its current | ||
| # status. The `backfill` actor is what marks these as synthesized — not | ||
| # the NULL from_status, which a genuine creation records too. | ||
| await db.execute( | ||
| """ | ||
| INSERT INTO task_events (task_id, from_status, to_status, actor, created_at) | ||
| SELECT id, NULL, status, 'backfill', COALESCE(created_at, updated_at) | ||
| FROM tasks | ||
| WHERE COALESCE(created_at, updated_at) IS NOT NULL | ||
| """ | ||
| ) | ||
|
|
||
| async with db.execute("SELECT COUNT(*) FROM task_events") as cursor: | ||
| seeded = (await cursor.fetchone())[0] | ||
| logger.info("v044: task_events created, seeded %d origin row(s)", seeded) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.