add favorite
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive_ce_flutter/hive_flutter.dart';
|
||||
|
||||
import 'package:worker/core/database/database_manager.dart';
|
||||
import 'package:worker/core/database/hive_service.dart';
|
||||
@@ -53,6 +54,9 @@ class HiveInitializer {
|
||||
|
||||
final dbManager = DatabaseManager();
|
||||
|
||||
// Migration: Delete old favoriteBox (deprecated, replaced with favoriteProductsBox)
|
||||
await _deleteLegacyFavoriteBox(verbose);
|
||||
|
||||
// Clear expired cache on app start
|
||||
await dbManager.clearExpiredCache();
|
||||
|
||||
@@ -97,6 +101,33 @@ class HiveInitializer {
|
||||
await hiveService.clearUserData();
|
||||
}
|
||||
|
||||
/// Delete legacy favoriteBox (migration helper)
|
||||
///
|
||||
/// The old favoriteBox stored FavoriteModel which has been removed.
|
||||
/// This method deletes the old box to prevent typeId errors.
|
||||
static Future<void> _deleteLegacyFavoriteBox(bool verbose) async {
|
||||
try {
|
||||
const legacyBoxName = 'favorite_box';
|
||||
|
||||
// Check if the old box exists
|
||||
if (await Hive.boxExists(legacyBoxName)) {
|
||||
if (verbose) {
|
||||
debugPrint('HiveInitializer: Deleting legacy favoriteBox...');
|
||||
}
|
||||
|
||||
// Delete the box from disk
|
||||
await Hive.deleteBoxFromDisk(legacyBoxName);
|
||||
|
||||
if (verbose) {
|
||||
debugPrint('HiveInitializer: Legacy favoriteBox deleted successfully');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('HiveInitializer: Error deleting legacy favoriteBox: $e');
|
||||
// Don't rethrow - this is just a cleanup operation
|
||||
}
|
||||
}
|
||||
|
||||
/// Get database statistics
|
||||
///
|
||||
/// Returns statistics about all Hive boxes.
|
||||
|
||||
Reference in New Issue
Block a user