Repository navigation
Conversation
The Maintenance dialog (OpenSAK-Org#1048) only checks the database file. Repair checks the data in it and fixes what can be fixed safely, like GSAK's Repair/Defrag. This is phase 1 of OpenSAK-Org#1051: the check framework, rows whose cache is missing, broken links, and checks that only report. Repair… opens a dialog that checks the database in the background without changing it. It lists every check that found something, with the number of problems, the fix and a few example GC codes. The user ticks what to fix. Checks marked "Report only" can't be ticked. "Make a backup first" is ticked and uses the backup core (OpenSAK-Org#952). The ticked fixes run in one transaction. Then the database is optimized, and compacted when more than a quarter of the file is free, as GSAK does. A summary follows and the check runs again. If quick_check fails, the file itself is damaged and SQLite can't repair it, so the dialog points to File → Restore from backup… (OpenSAK-Org#954) instead. Fixable checks: - rows that point to a missing cache, found with foreign_key_check (logs, waypoints, attributes, trackables, user notes): deleted - custom waypoints whose parent_gc_code points to a cache that isn't in the database: link cleared - waypoints whose parent_gc_code isn't their own cache's code: set from the cache, as the importer and macros do - the corrected flag set without corrected coordinates, so filters count the cache as corrected while the map and distances don't: flag cleared. The cache keeps its last_user_update (the OpenSAK-Org#1140 trigger would set it to now), because a repair is not a user edit. - companion database rows whose cache is gone: companion.cleanup() Report only: coordinates missing or out of range, corrected coordinates out of range, difficulty or terrain outside 1–5 or not in 0.5 steps, an empty GC code or name. There is no duplicate check. The unique constraints on attributes, log_id and waypoints exist in every database, and the importers don't fill their NULL gaps twice. The checks and fixes are in db/repair.py, which has no GUI code. The dialog works on the active database (its connections are released first, as for Compact) and on any other database in the list. The new texts are in all language files; the translations are machine-made. Part of OpenSAK-Org#1051
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add a Repair… action to the database Maintenance dialog
Part of #1051 (phase 1 of 3: check framework, rows without a cache, broken links, report-only checks).
What changed and why
The Maintenance dialog (#1048) checks the database file. This PR adds Repair…, which checks the data in it and fixes what can be fixed safely, like GSAK's Repair/Defrag.
The dialog:
If
quick_checkfails, the file itself is damaged and SQLite can't repair it, so the dialog points to File → Restore from backup… (#954) instead.It works on the active database (its connections are released first, as for Compact) and on any other database in the list. The checks and fixes are in the new module
db/repair.py, which has no GUI code.Checks
foreign_key_check: logs, waypoints, attributes, trackables, user notes)parent_gc_codepoints to a cache that isn't in the databaseparent_gc_codeisn't their own cache's codelast_user_updateis kept, because a repair is not a user edit (#1140 trigger).companion.cleanup()There is no duplicate check. The unique constraints on attributes,
logs.log_idand waypoints exist in every database (in the models since v0.2.0; migrations 2 and 21), and the importers replace a cache's waypoints and match logs by id.Tests
tests/unit-tests/test_db_repair_1051.pyuses a fixture database with one broken row of every kind. It checks the scan, each fix, and that only the ticked fixes run. It checks that a failed fix changes nothing, and that a second run finds nothing fixable. It also checks the dialog, including repairing the active database.Tested by hand on a real 1.3 GB database (152k caches, 732k logs).
The new texts are in all 11 language files. The translations are machine-made.