Skip to content

Commit

Permalink
attempt at rolling back bad database changes
Browse files Browse the repository at this point in the history
  • Loading branch information
polymorphicshade committed Apr 24, 2024
1 parent a9ec54f commit eb5bc4f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 41 deletions.
24 changes: 2 additions & 22 deletions app/schemas/org.schabi.newpipe.database.AppDatabase/10.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 10,
"identityHash": "377d92119f9bf8b38d1d4ec87453405e",
"identityHash": "7591e8039faa74d8c0517dc867af9d3e",
"entities": [
{
"tableName": "subscriptions",
Expand Down Expand Up @@ -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": [],
"setupQueries": [
"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')"
]
}
}
10 changes: 3 additions & 7 deletions app/src/main/java/org/schabi/newpipe/database/AppDatabase.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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.RoomDatabase;
Expand All @@ -22,8 +22,6 @@
import org.schabi.newpipe.database.playlist.model.PlaylistEntity;
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
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.StreamStateDAO;
import org.schabi.newpipe.database.stream.model.StreamEntity;
Expand All @@ -38,9 +36,9 @@
StreamEntity.class, StreamHistoryEntity.class, StreamStateEntity.class,
PlaylistEntity.class, PlaylistStreamEntity.class, PlaylistRemoteEntity.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 static final String DATABASE_NAME = "newpipe.db";
Expand All @@ -64,6 +62,4 @@ public abstract class AppDatabase extends RoomDatabase {
public abstract FeedGroupDAO feedGroupDAO();

public abstract SubscriptionDAO subscriptionDAO();

public abstract SponsorBlockWhitelistDAO sponsorBlockWhitelistDAO();
}
6 changes: 6 additions & 0 deletions app/src/main/java/org/schabi/newpipe/database/Migrations.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,15 @@ public void migrate(@NonNull final SupportSQLiteDatabase database) {
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)");
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) {
@Override
public void migrate(@NonNull final SupportSQLiteDatabase database) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,39 @@
import org.schabi.newpipe.NewPipeDatabase;
import org.schabi.newpipe.database.AppDatabase;
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.Maybe;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class SponsorBlockDataManager {
private final SponsorBlockWhitelistDAO sponsorBlockWhitelistTable;
private final SponsorBlockWhitelistDAO sponsorBlockWhitelistTable = null;

public SponsorBlockDataManager(final Context context) {
final AppDatabase database = NewPipeDatabase.getInstance(context);
sponsorBlockWhitelistTable = database.sponsorBlockWhitelistDAO();
}

public Maybe<Long> addToWhitelist(final String uploader) {
return Maybe.fromCallable(() -> {
final SponsorBlockWhitelistEntry entry = new SponsorBlockWhitelistEntry(uploader);
return sponsorBlockWhitelistTable.insert(entry);
}).subscribeOn(Schedulers.io());
// return Maybe.fromCallable(() -> {
// final SponsorBlockWhitelistEntry entry = new SponsorBlockWhitelistEntry(uploader);
// return sponsorBlockWhitelistTable.insert(entry);
// }).subscribeOn(Schedulers.io());
return Maybe.empty();
}

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) {
return Single.fromCallable(() -> sponsorBlockWhitelistTable.exists(uploader))
.subscribeOn(Schedulers.io());
// return Single.fromCallable(() -> sponsorBlockWhitelistTable.exists(uploader))
// .subscribeOn(Schedulers.io());
return Single.just(false);
}

public Completable clearWhitelist() {
return Completable.fromAction(sponsorBlockWhitelistTable::deleteAll);
// return Completable.fromAction(sponsorBlockWhitelistTable::deleteAll);
return Completable.complete();
}
}

0 comments on commit eb5bc4f

Please sign in to comment.