From 332d7fc60ace930f744d3f6622fe16504ae6a9b3 Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Wed, 1 Apr 2026 21:31:51 +0000 Subject: [PATCH] Update issue #2 storage design with new file structure --- .github/ISSUE_TEMPLATE/v2-simplify-storage.md | 62 ++++++++++++++----- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/v2-simplify-storage.md b/.github/ISSUE_TEMPLATE/v2-simplify-storage.md index be2f46b..03ba979 100644 --- a/.github/ISSUE_TEMPLATE/v2-simplify-storage.md +++ b/.github/ISSUE_TEMPLATE/v2-simplify-storage.md @@ -37,22 +37,56 @@ The bot works and 53/53 tests pass. But `db.py` is ~300 lines with subtle connec ## Proposal -**Replace SQLite with a per-user JSON file storage system.** +**Replace SQLite with a JSON file storage system — one directory per group or DM user.** ### Storage Design ``` data/ -└── users/ - └── {telegram_user_id}.json # one file per user +├── {group_id}/ +│ ├── group.json # group bounties (all bounties in this group) +│ └── {user_id}.json # user tracking within this group (which bounty IDs they track) +└── {user_id}/ + └── user.json # user's personal bounties (DM — only this user) ``` -**File structure (`users/{id}.json`):** +**Bot context lookup:** + +| Context | Entry point | +|---|---| +| In group (`chat_id = -100123`) | `data/-100123/group.json` | +| In DM (`chat_id = 123`) | `data/123/user.json` | + +**File: `data/{group_id}/group.json`** — group bounties: +```json +{ + "group_id": -100123, + "bounties": [ + { + "id": 1, + "created_by_user_id": 456, + "text": "Fix login bug", + "link": "https://github.com/example/repo/issues/1", + "due_date_ts": 1735689600, + "created_at": 1735603200 + } + ] +} +``` + +**File: `data/{group_id}/{user_id}.json`** — user tracking in a group: +```json +{ + "user_id": 456, + "tracked": [1, 5, 9] +} +``` + +**File: `data/{user_id}/user.json`** — user's personal bounties (DM): ```json { "user_id": 123, - "username": "alice", - "personal_bounties": [ + "bounties": [ { "id": 1, "text": "Fix login bug", @@ -60,25 +94,23 @@ data/ "due_date_ts": 1735689600, "created_at": 1735603200 } - ], - "tracked_bounties": [ - {"bounty_id": 5, "group_id": -1001, "created_at": 1735600000}, - {"bounty_id": 3, "group_id": null, "created_at": 1735590000} ] } ``` ### Key design decisions -1. **Single file per user** — No group-level files. Personal bounties live in the creator's file. Group bounties live in the creator's file with `group_id` set. +1. **Group/DM as directory** — `chat_id` is the gateway. Group → `data/{group_id}/group.json`. DM → `data/{user_id}/user.json`. No scanning needed. -2. **Bounty IDs are sequential integers per file** — Not global. Each user's file has its own `next_id` counter. This avoids coordination between users at the cost of non-global IDs (acceptable for personal use). +2. **Tracking is per-group-per-user** — `data/{group_id}/{user_id}.json` stores the list of bounty IDs this user tracks in this group. Simple, isolated. -3. **Cross-group tracking** — When Alice (in Group A) tracks a bounty created by Bob in Group B, Alice's file stores `{bounty_id: X, group_id: -100B}`. To display it, the bot loads Bob's file and finds bounty `X`. +3. **No cross-group access** — Group bounties live only in that group's file. A member of Group A cannot see or track Group B's bounties. -4. **No reminders in v1** — Drop the cron/reminder system entirely. The `reminder_log` table and `cron.py` are removed. Reminders can be added back as a v2 feature with a simpler design (e.g., just a "due soon" filter on `/my`). +4. **Bounty IDs are sequential integers per group** — Not global. Each `group.json` has its own `next_id` counter. -5. **No admin model in v1** — Drop `group_admins` table. Group bounties are open to anyone in the group to add/edit/delete. The creator can be the only one who can modify (enforced by `created_by_user_id` check). +5. **No reminders in v1** — Drop the cron/reminder system entirely. The `reminder_log` table and `cron.py` are removed. + +6. **No admin model in v1** — Anyone in the group can add bounties. Only the bounty creator can edit/delete (enforced by `created_by_user_id` check). ### Deleted components