Add optional time ranges and a calendar day view

Tasks can now have a start/end time on their deadline date. The new
Calendar view shows a day as a timeline (with a week strip and projected
repeats of recurring tasks), and the task form lists what is already
planned that day and flags overlaps. Existing databases are migrated to
schema v2 automatically, with a backup copy taken first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
goyban
2026-10-07 12:08:09 +02:00
parent c5b049edba
commit 509b1a1320
8 changed files with 447 additions and 19 deletions
+23 -3
View File
@@ -3,7 +3,7 @@ import sqlite3
from pathlib import Path
DB_PATH = os.environ.get("DB_PATH", "/data/whattodo.db")
SCHEMA_VERSION = 1
SCHEMA_VERSION = 2
DEFAULT_CATEGORIES = [
("Work", "#2563eb"),
@@ -30,7 +30,9 @@ CREATE TABLE IF NOT EXISTS tasks (
category_id INTEGER REFERENCES categories(id) ON DELETE SET NULL,
priority INTEGER NOT NULL DEFAULT 0,
due_date TEXT,
tags TEXT NOT NULL DEFAULT '[]',
start_time TEXT,
end_time TEXT,
tags TEXT NOT NULL DEFAULT '[]',
recurrence TEXT NOT NULL DEFAULT 'none',
recur_interval INTEGER NOT NULL DEFAULT 1,
done INTEGER NOT NULL DEFAULT 0,
@@ -65,7 +67,9 @@ def init() -> None:
conn.execute("PRAGMA journal_mode = WAL")
conn.executescript(SCHEMA)
row = conn.execute("SELECT value FROM meta WHERE key = 'schema_version'").fetchone()
if row is None:
if row is not None and int(row["value"]) < SCHEMA_VERSION:
migrate(conn, int(row["value"]))
elif row is None:
# Fresh database: seed default categories.
with conn:
for i, (name, color) in enumerate(DEFAULT_CATEGORIES):
@@ -79,3 +83,19 @@ def init() -> None:
)
finally:
conn.close()
def migrate(conn: sqlite3.Connection, version: int) -> None:
# Keep a copy of the database as it was before migrating, next to it.
backup = sqlite3.connect(f"{DB_PATH}.before-v{SCHEMA_VERSION}.bak")
try:
conn.backup(backup)
finally:
backup.close()
with conn:
if version < 2:
conn.execute("ALTER TABLE tasks ADD COLUMN start_time TEXT")
conn.execute("ALTER TABLE tasks ADD COLUMN end_time TEXT")
conn.execute(
"UPDATE meta SET value = ? WHERE key = 'schema_version'", (str(SCHEMA_VERSION),)
)