882632b7ce
- ops: paying marks the current charge paid (paid_for, persisted) instead of jumping to the next date; repeat_sub moves to the next period or closes the subscription. Paid-and-undecided subscriptions leave reminders and show in agenda['paid']. update_sub can set paid; tasks reopen when their status goes back; delete for subs and routines (BroV only, /api/delete); /api/tasks?all=1 and /api/subs?all=1. - Bot: «₽ Оплачено?» on reminders, then «🔁 Да, <date> / Нет, закрыть»; after paying by text it asks the same with buttons. - BroV: «Оплачено?» everywhere; «Оплачено — повторить?» section under the notch; «Весь план»: forms to edit or create tasks (title, description, status, due, company), subscriptions (amount, currency, period, date, reminder, company, paid, active) and routines, delete with confirmation, «+» per list, done tasks on demand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
3.3 KiB
Python
83 lines
3.3 KiB
Python
"""SQLite storage for BroV Ops: tasks (with subtasks and time tracking), subscriptions
|
|
with their payments, routines with their history, and a log of sent reminders."""
|
|
import sqlite3
|
|
|
|
SCHEMA = """
|
|
CREATE TABLE IF NOT EXISTS tasks (
|
|
id INTEGER PRIMARY KEY,
|
|
parent_id INTEGER REFERENCES tasks(id) ON DELETE CASCADE,
|
|
title TEXT NOT NULL,
|
|
notes TEXT NOT NULL DEFAULT '',
|
|
client TEXT NOT NULL DEFAULT '', -- saga / planet9 / home / …
|
|
status TEXT NOT NULL DEFAULT 'todo', -- todo | doing | done
|
|
due TEXT, -- YYYY-MM-DD
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
done_at TEXT
|
|
);
|
|
CREATE TABLE IF NOT EXISTS time_entries (
|
|
id INTEGER PRIMARY KEY,
|
|
task_id INTEGER NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
|
|
started TEXT NOT NULL, -- ISO datetime, UTC
|
|
stopped TEXT
|
|
);
|
|
CREATE TABLE IF NOT EXISTS subscriptions (
|
|
id INTEGER PRIMARY KEY,
|
|
name TEXT NOT NULL,
|
|
amount REAL NOT NULL DEFAULT 0,
|
|
currency TEXT NOT NULL DEFAULT 'RUB',
|
|
period TEXT NOT NULL DEFAULT 'month', -- day | week | month | year
|
|
every INTEGER NOT NULL DEFAULT 1, -- every N periods
|
|
next_date TEXT NOT NULL, -- YYYY-MM-DD of the next charge
|
|
remind_days INTEGER NOT NULL DEFAULT 3,
|
|
notes TEXT NOT NULL DEFAULT '',
|
|
active INTEGER NOT NULL DEFAULT 1,
|
|
client TEXT NOT NULL DEFAULT '', -- company it's paid for: saga / planet9 / home / …
|
|
paid_for TEXT -- = next_date once that charge is paid (until «repeat?» is answered)
|
|
);
|
|
CREATE TABLE IF NOT EXISTS payments (
|
|
id INTEGER PRIMARY KEY,
|
|
sub_id INTEGER NOT NULL REFERENCES subscriptions(id) ON DELETE CASCADE,
|
|
paid_on TEXT NOT NULL,
|
|
amount REAL NOT NULL
|
|
);
|
|
CREATE TABLE IF NOT EXISTS routines (
|
|
id INTEGER PRIMARY KEY,
|
|
title TEXT NOT NULL,
|
|
every_days INTEGER NOT NULL,
|
|
next_date TEXT NOT NULL,
|
|
notes TEXT NOT NULL DEFAULT '',
|
|
active INTEGER NOT NULL DEFAULT 1
|
|
);
|
|
CREATE TABLE IF NOT EXISTS routine_log (
|
|
id INTEGER PRIMARY KEY,
|
|
routine_id INTEGER NOT NULL REFERENCES routines(id) ON DELETE CASCADE,
|
|
done_on TEXT NOT NULL,
|
|
note TEXT NOT NULL DEFAULT ''
|
|
);
|
|
CREATE TABLE IF NOT EXISTS settings (
|
|
key TEXT PRIMARY KEY,
|
|
value TEXT NOT NULL
|
|
);
|
|
CREATE TABLE IF NOT EXISTS reminders_sent (
|
|
kind TEXT NOT NULL, -- task | sub | routine | digest
|
|
ref INTEGER NOT NULL,
|
|
day TEXT NOT NULL, -- YYYY-MM-DD the reminder was sent for
|
|
PRIMARY KEY (kind, ref, day)
|
|
);
|
|
"""
|
|
|
|
|
|
def connect(path: str) -> sqlite3.Connection:
|
|
con = sqlite3.connect(path, check_same_thread=False, isolation_level=None)
|
|
con.row_factory = sqlite3.Row
|
|
con.execute("PRAGMA foreign_keys = ON")
|
|
con.execute("PRAGMA journal_mode = WAL")
|
|
con.executescript(SCHEMA)
|
|
# Databases created before subscriptions had a company.
|
|
cols = {r["name"] for r in con.execute("PRAGMA table_info(subscriptions)")}
|
|
if "client" not in cols:
|
|
con.execute("ALTER TABLE subscriptions ADD COLUMN client TEXT NOT NULL DEFAULT ''")
|
|
if "paid_for" not in cols:
|
|
con.execute("ALTER TABLE subscriptions ADD COLUMN paid_for TEXT")
|
|
return con
|