mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-04-20 23:07:26 -04:00
[app] migrate old DB only after pre-populating DB to ensure default repos have been added
This commit is contained in:
@@ -57,7 +57,6 @@ import org.fdroid.database.Repository;
|
||||
import org.fdroid.fdroid.Preferences.ChangeListener;
|
||||
import org.fdroid.fdroid.Preferences.Theme;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
import org.fdroid.fdroid.data.ContentProviderMigrator;
|
||||
import org.fdroid.fdroid.data.DBHelper;
|
||||
import org.fdroid.fdroid.installer.ApkFileProvider;
|
||||
import org.fdroid.fdroid.installer.InstallHistoryService;
|
||||
@@ -415,17 +414,6 @@ public class FDroidApp extends Application implements androidx.work.Configuratio
|
||||
if (Preferences.get().isScanRemovableStorageEnabled()) {
|
||||
SDCardScannerService.scan(this);
|
||||
}
|
||||
|
||||
// Migrate repos from old content providers to new Room-based DB.
|
||||
// Added end of 2022 for alphas, can be removed after sufficient time has passed.
|
||||
Utils.runOffUiThread(() -> {
|
||||
ContentProviderMigrator migrator = new ContentProviderMigrator();
|
||||
if (migrator.needsMigration(this)) {
|
||||
migrator.migrateOldRepos(this, db);
|
||||
migrator.removeOldDb(this);
|
||||
UpdateService.forceUpdateRepo(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,18 +16,18 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class ContentProviderMigrator {
|
||||
final class ContentProviderMigrator {
|
||||
|
||||
private static final String OLD_DB_NAME = "fdroid";
|
||||
|
||||
public boolean needsMigration(Context context) {
|
||||
boolean needsMigration(Context context) {
|
||||
for (String db : context.databaseList()) {
|
||||
if (OLD_DB_NAME.equals(db)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void migrateOldRepos(Context context, FDroidDatabase db) {
|
||||
void migrateOldRepos(Context context, FDroidDatabase db) {
|
||||
RepositoryDao repoDao = db.getRepositoryDao();
|
||||
List<Repository> repos = repoDao.getRepositories();
|
||||
int weight = repos.isEmpty() ? 0 : repos.get(repos.size() - 1).getWeight();
|
||||
@@ -86,7 +86,7 @@ public final class ContentProviderMigrator {
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOldDb(Context context) {
|
||||
void removeOldDb(Context context) {
|
||||
context.deleteDatabase(OLD_DB_NAME);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.fdroid.database.FDroidDatabase;
|
||||
import org.fdroid.database.FDroidDatabaseHolder;
|
||||
import org.fdroid.database.InitialRepository;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.UpdateService;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
@@ -79,6 +80,14 @@ public class DBHelper {
|
||||
);
|
||||
db.getRepositoryDao().insert(repo);
|
||||
}
|
||||
// Migrate repos from old content providers to new Room-based DB.
|
||||
// Added end of 2022 for alphas, can be removed after sufficient time has passed.
|
||||
ContentProviderMigrator migrator = new ContentProviderMigrator();
|
||||
if (migrator.needsMigration(context)) {
|
||||
migrator.migrateOldRepos(context, db);
|
||||
migrator.removeOldDb(context);
|
||||
UpdateService.forceUpdateRepo(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user