sossoldi icon indicating copy to clipboard operation
sossoldi copied to clipboard

feat: Implement database migration system

Open xDefcon opened this issue 1 year ago • 3 comments

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:

  1. Each migration has a version number and description
  2. The MigrationManager tracks database versions and applies migrations in sequence
  3. New migrations are registered in migration_registry.dart
  4. 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 with kDebugMode checks for development visibility. A future enhancement should implement a proper logging system (using the logger package 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?

xDefcon avatar Mar 15 '25 12:03 xDefcon

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.

xDefcon avatar Mar 15 '25 12:03 xDefcon

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 avatar Mar 15 '25 17:03 mikev-cw

@mikev-cw Yes I am, with the same username.

xDefcon avatar Mar 15 '25 18:03 xDefcon

@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!

mikev-cw avatar Mar 22 '25 16:03 mikev-cw