fix: Backup database automatically on migration for data safety#162
Merged
Conversation
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.
Pull Request Checklist
mainbranch of tmpo.Closes #139
Description
This pull request introduces a more robust and reliable database migration system to handle schema changes for legacy and future versions of the application. It ensures that schema upgrades are tracked with explicit migration keys, creates pre-migration backups for safety, and adds comprehensive tests to cover migration scenarios. The most important changes are summarized below:
Database Migration System Improvements:
Migration002_EntrySchema) to ensure thetime_entriestable has thehourly_rateandmilestone_namecolumns and supporting indexes. This replaces the previous ad-hoc approach inInitialize. [1] [2]hasPendingMigrationsmethod to detect if any migrations are needed, and themigrateEntrySchemamethod to bring legacy databases up to date in an idempotent and reliable way.columnExistsfunction that uses SQLite's PRAGMA table_info for accuracy.Backup and Migration Safety:
Initializeto create a pre-migration backup (with a-premigrationsuffix) if there are pending migrations, and to automatically remove the backup upon successful migration or retain it if migration fails. This prevents data loss during upgrades. [1] [2]createBackupmethod that supports custom filename suffixes. [1] [2]Testing Enhancements:
Code Cleanup:
Initialize. [1] [2]These changes make schema migrations safer and more maintainable, reduce risk of data loss, and improve test coverage for database upgrades.