diff --git a/lib/data/database_repository.dart b/lib/data/database_repository.dart index c43dbf70..ba59c244 100644 --- a/lib/data/database_repository.dart +++ b/lib/data/database_repository.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:equatable/equatable.dart'; +import 'package:meta/meta.dart'; import 'package:sembast/sembast.dart'; /// Handles the local persistence to the database @@ -139,7 +140,8 @@ class DatabaseRepositoryImpl implements DatabaseRepository { } } -extension on DatabaseStore { +extension StoreKeys on DatabaseStore { + @visibleForTesting String get key { switch (this) { case DatabaseStore.decks: diff --git a/lib/data/sembast_database.dart b/lib/data/sembast_database.dart index 5cb81867..101c52bb 100644 --- a/lib/data/sembast_database.dart +++ b/lib/data/sembast_database.dart @@ -9,7 +9,7 @@ import 'package:sembast/sembast_io.dart'; const _schemaVersion = 1; const _dbName = 'memo_sembast.db'; -/// Opens this application's [Database], creating a new one if non-existing +/// Opens this application's [Database], creating a new one if nonexistent Future<Database> openDatabase() async { final dir = await getApplicationDocumentsDirectory(); // Make sure that the application documents directory exists @@ -17,14 +17,11 @@ Future<Database> openDatabase() async { final dbPath = path.join(dir.path, _dbName); - return databaseFactoryIo.openDatabase(dbPath, version: _schemaVersion, onVersionChanged: _applyMigrations); + return databaseFactoryIo.openDatabase(dbPath, version: _schemaVersion, onVersionChanged: applyMigrations); } -Future<void> _applyMigrations(Database db, int oldVersion, int newVersion) async { - if (oldVersion == newVersion) { - return SynchronousFuture(null); - } - +@visibleForTesting +Future<void> applyMigrations(Database db, int oldVersion, int newVersion) async { // Call the necessary migrations in order }