2023-03-23 02:36:44 +01:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
2025-02-20 00:57:32 +05:30
|
|
|
import 'package:immich_mobile/domain/models/store.model.dart';
|
2024-04-30 21:36:40 -05:00
|
|
|
import 'package:immich_mobile/entities/store.entity.dart';
|
2026-03-11 12:07:27 -05:00
|
|
|
import 'package:immich_mobile/infrastructure/repositories/network.repository.dart';
|
|
|
|
|
import 'package:immich_mobile/services/api.service.dart';
|
2023-02-09 18:32:08 +01:00
|
|
|
|
2026-03-11 12:07:27 -05:00
|
|
|
const int targetVersion = 25;
|
2024-05-14 17:35:37 +02:00
|
|
|
|
2026-04-15 23:00:27 +05:30
|
|
|
Future<void> migrateDatabaseIfNeeded() async {
|
2025-04-04 01:12:35 +05:30
|
|
|
final int version = Store.get(StoreKey.version, targetVersion);
|
2026-03-07 18:07:34 +00:00
|
|
|
|
2026-03-11 12:07:27 -05:00
|
|
|
if (version < 25) {
|
|
|
|
|
final accessToken = Store.tryGet(StoreKey.accessToken);
|
|
|
|
|
if (accessToken != null && accessToken.isNotEmpty) {
|
|
|
|
|
final serverUrls = ApiService.getServerUrls();
|
|
|
|
|
if (serverUrls.isNotEmpty) {
|
|
|
|
|
await NetworkRepository.setHeaders(ApiService.getRequestHeaders(), serverUrls, token: accessToken);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 23:00:27 +05:30
|
|
|
await Store.put(StoreKey.version, targetVersion);
|
|
|
|
|
return;
|
2025-04-04 01:12:35 +05:30
|
|
|
}
|