feat: Implement database migration system
Changes Made
- Added database migration system Implemented a structured migration system to handle database schema evolution systematically.
- Initial Schema (_createDB) is now handled as a migration
- Added docs to the database migration system
How It Works
The migration system automatically handles schema changes through versioned migration classes:
- Each migration has a version number and description
- The MigrationManager tracks database versions and applies migrations in sequence
- New migrations are registered in migration_registry.dart
- When upgrading the database, only migrations with newer version numbers are applied in the specified order
This approach provides a reliable way to evolve the database schema while maintaining backward compatibility with existing data.
Additional Considerations
- Migration Rollback: Rollback functionality is not implemented by purpose (database versions can only go up). To modify a previous migration, create a new one with the corrective changes.
-
Logging: Currently using
print()statements wrapped withkDebugModechecks for development visibility. A future enhancement should implement a proper logging system (using theloggerpackage or a custom logging service which is not the purpose of this PR) - Migration Testing: Each migration should be tested independently to ensure it works correctly both on fresh installs and when upgrading from previous versions. Maybe add some tests related to this?
Related to issue #261
@mikev-cw Could you review this? I'd also appreciate your feedback on the additional considerations mentioned above. Thanks!
This PR requires testing, possibly including automated tests.
Super, of course I will. I think this could be a valuable addition and i want to go super deep this contribution though! :D Give me some time. @xDefcon are you on our Discord, in case i need some clarifications?
@mikev-cw Yes I am, with the same username.
@xDefcon I'm merging this, also without tests. We need to do a release next days and we want to have this feature ready for that. Please, if you can, create an issue for tests. Thank you so much!