attempt at rolling back bad database changes

This commit is contained in:
polymorphicshade 2024-04-23 23:06:22 -06:00
parent a9ec54f908
commit eb5bc4fa35
4 changed files with 24 additions and 41 deletions

View file

@ -2,7 +2,7 @@
"formatVersion": 1, "formatVersion": 1,
"database": { "database": {
"version": 10, "version": 10,
"identityHash": "377d92119f9bf8b38d1d4ec87453405e", "identityHash": "7591e8039faa74d8c0517dc867af9d3e",
"entities": [ "entities": [
{ {
"tableName": "subscriptions", "tableName": "subscriptions",
@ -719,32 +719,12 @@
] ]
} }
] ]
},
{
"tableName": "sponsorblock_whitelist",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uploader` TEXT NOT NULL, PRIMARY KEY(`uploader`))",
"fields": [
{
"fieldPath": "uploader",
"columnName": "uploader",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"uploader"
]
},
"indices": [],
"foreignKeys": []
} }
], ],
"views": [], "views": [],
"setupQueries": [ "setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '377d92119f9bf8b38d1d4ec87453405e')" "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7591e8039faa74d8c0517dc867af9d3e')"
] ]
} }
} }

View file

@ -1,6 +1,6 @@
package org.schabi.newpipe.database; package org.schabi.newpipe.database;
import static org.schabi.newpipe.database.Migrations.DB_VER_10; import static org.schabi.newpipe.database.Migrations.DB_VER_9;
import androidx.room.Database; import androidx.room.Database;
import androidx.room.RoomDatabase; import androidx.room.RoomDatabase;
@ -22,8 +22,6 @@ import org.schabi.newpipe.database.playlist.dao.PlaylistStreamDAO;
import org.schabi.newpipe.database.playlist.model.PlaylistEntity; import org.schabi.newpipe.database.playlist.model.PlaylistEntity;
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity; import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
import org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity; import org.schabi.newpipe.database.playlist.model.PlaylistStreamEntity;
import org.schabi.newpipe.database.sponsorblock.dao.SponsorBlockWhitelistDAO;
import org.schabi.newpipe.database.sponsorblock.dao.SponsorBlockWhitelistEntry;
import org.schabi.newpipe.database.stream.dao.StreamDAO; import org.schabi.newpipe.database.stream.dao.StreamDAO;
import org.schabi.newpipe.database.stream.dao.StreamStateDAO; import org.schabi.newpipe.database.stream.dao.StreamStateDAO;
import org.schabi.newpipe.database.stream.model.StreamEntity; import org.schabi.newpipe.database.stream.model.StreamEntity;
@ -38,9 +36,9 @@ import org.schabi.newpipe.database.subscription.SubscriptionEntity;
StreamEntity.class, StreamHistoryEntity.class, StreamStateEntity.class, StreamEntity.class, StreamHistoryEntity.class, StreamStateEntity.class,
PlaylistEntity.class, PlaylistStreamEntity.class, PlaylistRemoteEntity.class, PlaylistEntity.class, PlaylistStreamEntity.class, PlaylistRemoteEntity.class,
FeedEntity.class, FeedGroupEntity.class, FeedGroupSubscriptionEntity.class, FeedEntity.class, FeedGroupEntity.class, FeedGroupSubscriptionEntity.class,
FeedLastUpdatedEntity.class, SponsorBlockWhitelistEntry.class FeedLastUpdatedEntity.class
}, },
version = DB_VER_10 version = DB_VER_9
) )
public abstract class AppDatabase extends RoomDatabase { public abstract class AppDatabase extends RoomDatabase {
public static final String DATABASE_NAME = "newpipe.db"; public static final String DATABASE_NAME = "newpipe.db";
@ -64,6 +62,4 @@ public abstract class AppDatabase extends RoomDatabase {
public abstract FeedGroupDAO feedGroupDAO(); public abstract FeedGroupDAO feedGroupDAO();
public abstract SubscriptionDAO subscriptionDAO(); public abstract SubscriptionDAO subscriptionDAO();
public abstract SponsorBlockWhitelistDAO sponsorBlockWhitelistDAO();
} }

View file

@ -252,9 +252,15 @@ public final class Migrations {
database.execSQL("DELETE FROM search_history WHERE id NOT IN (SELECT id FROM (SELECT " database.execSQL("DELETE FROM search_history WHERE id NOT IN (SELECT id FROM (SELECT "
+ "MIN(id) as id FROM search_history GROUP BY trim(search), service_id ) tmp)"); + "MIN(id) as id FROM search_history GROUP BY trim(search), service_id ) tmp)");
database.execSQL("UPDATE search_history SET search = trim(search)"); database.execSQL("UPDATE search_history SET search = trim(search)");
// TODO: remove later - this meant to be a temporary fix for
// "rolling back" the database to fix poly's dumb mistake...
database.execSQL("DROP TABLE `sponsorblock_whitelist`");
MIGRATION_9_10.migrate(database);
} }
}; };
// TODO: change back to MIGRATION_8_9 = new Migration(DB_VER_8, DB_VER_9)
public static final Migration MIGRATION_9_10 = new Migration(DB_VER_9, DB_VER_10) { public static final Migration MIGRATION_9_10 = new Migration(DB_VER_9, DB_VER_10) {
@Override @Override
public void migrate(@NonNull final SupportSQLiteDatabase database) { public void migrate(@NonNull final SupportSQLiteDatabase database) {

View file

@ -5,38 +5,39 @@ import android.content.Context;
import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.NewPipeDatabase;
import org.schabi.newpipe.database.AppDatabase; import org.schabi.newpipe.database.AppDatabase;
import org.schabi.newpipe.database.sponsorblock.dao.SponsorBlockWhitelistDAO; import org.schabi.newpipe.database.sponsorblock.dao.SponsorBlockWhitelistDAO;
import org.schabi.newpipe.database.sponsorblock.dao.SponsorBlockWhitelistEntry;
import io.reactivex.rxjava3.core.Completable; import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Maybe; import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.Single; import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.schedulers.Schedulers;
public class SponsorBlockDataManager { public class SponsorBlockDataManager {
private final SponsorBlockWhitelistDAO sponsorBlockWhitelistTable; private final SponsorBlockWhitelistDAO sponsorBlockWhitelistTable = null;
public SponsorBlockDataManager(final Context context) { public SponsorBlockDataManager(final Context context) {
final AppDatabase database = NewPipeDatabase.getInstance(context); final AppDatabase database = NewPipeDatabase.getInstance(context);
sponsorBlockWhitelistTable = database.sponsorBlockWhitelistDAO();
} }
public Maybe<Long> addToWhitelist(final String uploader) { public Maybe<Long> addToWhitelist(final String uploader) {
return Maybe.fromCallable(() -> { // return Maybe.fromCallable(() -> {
final SponsorBlockWhitelistEntry entry = new SponsorBlockWhitelistEntry(uploader); // final SponsorBlockWhitelistEntry entry = new SponsorBlockWhitelistEntry(uploader);
return sponsorBlockWhitelistTable.insert(entry); // return sponsorBlockWhitelistTable.insert(entry);
}).subscribeOn(Schedulers.io()); // }).subscribeOn(Schedulers.io());
return Maybe.empty();
} }
public Completable removeFromWhitelist(final String uploader) { public Completable removeFromWhitelist(final String uploader) {
return Completable.fromAction(() -> sponsorBlockWhitelistTable.deleteByUploader(uploader)); // return Completable.fromAction(() -> sponsorBlockWhitelistTable.deleteByUploader(uploader));
return Completable.complete();
} }
public Single<Boolean> isWhiteListed(final String uploader) { public Single<Boolean> isWhiteListed(final String uploader) {
return Single.fromCallable(() -> sponsorBlockWhitelistTable.exists(uploader)) // return Single.fromCallable(() -> sponsorBlockWhitelistTable.exists(uploader))
.subscribeOn(Schedulers.io()); // .subscribeOn(Schedulers.io());
return Single.just(false);
} }
public Completable clearWhitelist() { public Completable clearWhitelist() {
return Completable.fromAction(sponsorBlockWhitelistTable::deleteAll); // return Completable.fromAction(sponsorBlockWhitelistTable::deleteAll);
return Completable.complete();
} }
} }