Repository navigation
Deleting a medication keeps its dose history - #29
Conversation
The confirm dialog promised "Past history is kept", but deleteMedication did a hard DELETE and ON DELETE CASCADE removed every dose with it: taken/missed history, fired_at and the adherence grid, saved into the next backup too. Now it's a soft delete: medications.deleted (DB v3), set together with active = 0. Deleted meds are hidden from the user-facing lists, kept in backups (old files without the flag still load), and their upcoming pending doses are still cancelled through the scheduler's orphan pass. The missed-dose notification skips deleted meds, since the Today screen can't clear those. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
What
The delete dialog says "Its upcoming alarms will be cancelled. Past history is kept." It wasn't true:
deleteMedicationdid a hardDELETE, anddoseshasON DELETE CASCADEwith foreign keys on, so every taken/missed dose,fired_atand the adherence-grid history for that medication was erased. The next automatic backup then saved the loss.Now deleting is a soft delete:
medications.deletedcolumn, DB version 2 → 3 (ALTER TABLE ... ADD COLUMN, default 0).deleteMedicationsetsdeleted = 1, active = 0(lib/data/database.dart).medications()hides deleted ones unlessincludeDeleted: true. Backups use it, and write/read the flag. Old backup files without it still load as not deleted (backup_format.dart,backup_service.dart).scheduler.sync(). The orphan pass then cancels and removes the med's upcoming pending doses, which the cascade used to do. Past doses stay.scheduler.dart).AGENTS.mdnotes the soft delete.Merges cleanly with #28 (checked locally).
Tests
keeps a soft-deleted medication and its dose history through a round-trip,a backup from before the deleted flag decodes as not deleted(test/backup_test.dart).TZ=Europe/Warsaw flutter test: 38 passed.flutter analyze: clean.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes