mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-30 23:03:00 +00:00 
			
		
		
		
	Added migration to new database
This commit is contained in:
		| @@ -33,7 +33,8 @@ class DatabaseMigrationTest { | |||||||
|     @get:Rule |     @get:Rule | ||||||
|     val testHelper = MigrationTestHelper( |     val testHelper = MigrationTestHelper( | ||||||
|         InstrumentationRegistry.getInstrumentation(), |         InstrumentationRegistry.getInstrumentation(), | ||||||
|         AppDatabase::class.java.canonicalName, FrameworkSQLiteOpenHelperFactory() |         AppDatabase::class.java.canonicalName, | ||||||
|  |         FrameworkSQLiteOpenHelperFactory() | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|     @Test |     @Test | ||||||
| @@ -42,7 +43,8 @@ class DatabaseMigrationTest { | |||||||
|  |  | ||||||
|         databaseInV2.run { |         databaseInV2.run { | ||||||
|             insert( |             insert( | ||||||
|                 "streams", SQLiteDatabase.CONFLICT_FAIL, |                 "streams", | ||||||
|  |                 SQLiteDatabase.CONFLICT_FAIL, | ||||||
|                 ContentValues().apply { |                 ContentValues().apply { | ||||||
|                     put("service_id", DEFAULT_SERVICE_ID) |                     put("service_id", DEFAULT_SERVICE_ID) | ||||||
|                     put("url", DEFAULT_URL) |                     put("url", DEFAULT_URL) | ||||||
| @@ -54,14 +56,16 @@ class DatabaseMigrationTest { | |||||||
|                 } |                 } | ||||||
|             ) |             ) | ||||||
|             insert( |             insert( | ||||||
|                 "streams", SQLiteDatabase.CONFLICT_FAIL, |                 "streams", | ||||||
|  |                 SQLiteDatabase.CONFLICT_FAIL, | ||||||
|                 ContentValues().apply { |                 ContentValues().apply { | ||||||
|                     put("service_id", DEFAULT_SECOND_SERVICE_ID) |                     put("service_id", DEFAULT_SECOND_SERVICE_ID) | ||||||
|                     put("url", DEFAULT_SECOND_URL) |                     put("url", DEFAULT_SECOND_URL) | ||||||
|                 } |                 } | ||||||
|             ) |             ) | ||||||
|             insert( |             insert( | ||||||
|                 "streams", SQLiteDatabase.CONFLICT_FAIL, |                 "streams", | ||||||
|  |                 SQLiteDatabase.CONFLICT_FAIL, | ||||||
|                 ContentValues().apply { |                 ContentValues().apply { | ||||||
|                     put("service_id", DEFAULT_SERVICE_ID) |                     put("service_id", DEFAULT_SERVICE_ID) | ||||||
|                 } |                 } | ||||||
| @@ -70,18 +74,31 @@ class DatabaseMigrationTest { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         testHelper.runMigrationsAndValidate( |         testHelper.runMigrationsAndValidate( | ||||||
|             AppDatabase.DATABASE_NAME, Migrations.DB_VER_3, |             AppDatabase.DATABASE_NAME, | ||||||
|             true, Migrations.MIGRATION_2_3 |             Migrations.DB_VER_3, | ||||||
|  |             true, | ||||||
|  |             Migrations.MIGRATION_2_3 | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|         testHelper.runMigrationsAndValidate( |         testHelper.runMigrationsAndValidate( | ||||||
|             AppDatabase.DATABASE_NAME, Migrations.DB_VER_4, |             AppDatabase.DATABASE_NAME, | ||||||
|             true, Migrations.MIGRATION_3_4 |             Migrations.DB_VER_4, | ||||||
|  |             true, | ||||||
|  |             Migrations.MIGRATION_3_4 | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|         testHelper.runMigrationsAndValidate( |         testHelper.runMigrationsAndValidate( | ||||||
|             AppDatabase.DATABASE_NAME, Migrations.DB_VER_5, |             AppDatabase.DATABASE_NAME, | ||||||
|             true, Migrations.MIGRATION_4_5 |             Migrations.DB_VER_5, | ||||||
|  |             true, | ||||||
|  |             Migrations.MIGRATION_4_5 | ||||||
|  |         ) | ||||||
|  |  | ||||||
|  |         testHelper.runMigrationsAndValidate( | ||||||
|  |             AppDatabase.DATABASE_NAME, | ||||||
|  |             Migrations.DB_VER_6, | ||||||
|  |             true, | ||||||
|  |             Migrations.MIGRATION_5_6 | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|         val migratedDatabaseV3 = getMigratedDatabase() |         val migratedDatabaseV3 = getMigratedDatabase() | ||||||
| @@ -121,7 +138,8 @@ class DatabaseMigrationTest { | |||||||
|     private fun getMigratedDatabase(): AppDatabase { |     private fun getMigratedDatabase(): AppDatabase { | ||||||
|         val database: AppDatabase = Room.databaseBuilder( |         val database: AppDatabase = Room.databaseBuilder( | ||||||
|             ApplicationProvider.getApplicationContext(), |             ApplicationProvider.getApplicationContext(), | ||||||
|             AppDatabase::class.java, AppDatabase.DATABASE_NAME |             AppDatabase::class.java, | ||||||
|  |             AppDatabase.DATABASE_NAME | ||||||
|         ) |         ) | ||||||
|             .build() |             .build() | ||||||
|         testHelper.closeWhenFinished(database) |         testHelper.closeWhenFinished(database) | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ import static org.schabi.newpipe.database.Migrations.MIGRATION_1_2; | |||||||
| import static org.schabi.newpipe.database.Migrations.MIGRATION_2_3; | import static org.schabi.newpipe.database.Migrations.MIGRATION_2_3; | ||||||
| import static org.schabi.newpipe.database.Migrations.MIGRATION_3_4; | import static org.schabi.newpipe.database.Migrations.MIGRATION_3_4; | ||||||
| import static org.schabi.newpipe.database.Migrations.MIGRATION_4_5; | import static org.schabi.newpipe.database.Migrations.MIGRATION_4_5; | ||||||
|  | import static org.schabi.newpipe.database.Migrations.MIGRATION_5_6; | ||||||
|  |  | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.database.Cursor; | import android.database.Cursor; | ||||||
| @@ -24,7 +25,8 @@ public final class NewPipeDatabase { | |||||||
|     private static AppDatabase getDatabase(final Context context) { |     private static AppDatabase getDatabase(final Context context) { | ||||||
|         return Room |         return Room | ||||||
|                 .databaseBuilder(context.getApplicationContext(), AppDatabase.class, DATABASE_NAME) |                 .databaseBuilder(context.getApplicationContext(), AppDatabase.class, DATABASE_NAME) | ||||||
|                 .addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5) |                 .addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, | ||||||
|  |                         MIGRATION_5_6) | ||||||
|                 .build(); |                 .build(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| package org.schabi.newpipe.database; | package org.schabi.newpipe.database; | ||||||
|  |  | ||||||
| import static org.schabi.newpipe.database.Migrations.DB_VER_5; | import static org.schabi.newpipe.database.Migrations.DB_VER_6; | ||||||
|  |  | ||||||
| import androidx.room.Database; | import androidx.room.Database; | ||||||
| import androidx.room.RoomDatabase; | import androidx.room.RoomDatabase; | ||||||
| @@ -38,7 +38,7 @@ import org.schabi.newpipe.database.subscription.SubscriptionEntity; | |||||||
|                 FeedEntity.class, FeedGroupEntity.class, FeedGroupSubscriptionEntity.class, |                 FeedEntity.class, FeedGroupEntity.class, FeedGroupSubscriptionEntity.class, | ||||||
|                 FeedLastUpdatedEntity.class |                 FeedLastUpdatedEntity.class | ||||||
|         }, |         }, | ||||||
|         version = DB_VER_5 |         version = DB_VER_6 | ||||||
| ) | ) | ||||||
| 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"; | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ public final class Migrations { | |||||||
|     public static final int DB_VER_3 = 3; |     public static final int DB_VER_3 = 3; | ||||||
|     public static final int DB_VER_4 = 4; |     public static final int DB_VER_4 = 4; | ||||||
|     public static final int DB_VER_5 = 5; |     public static final int DB_VER_5 = 5; | ||||||
|  |     public static final int DB_VER_6 = 6; | ||||||
|  |  | ||||||
|     private static final String TAG = Migrations.class.getName(); |     private static final String TAG = Migrations.class.getName(); | ||||||
|     public static final boolean DEBUG = MainActivity.DEBUG; |     public static final boolean DEBUG = MainActivity.DEBUG; | ||||||
| @@ -188,6 +189,14 @@ public final class Migrations { | |||||||
|         } |         } | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |     public static final Migration MIGRATION_5_6 = new Migration(DB_VER_5, DB_VER_6) { | ||||||
|  |         @Override | ||||||
|  |         public void migrate(@NonNull final SupportSQLiteDatabase database) { | ||||||
|  |             database.execSQL("ALTER TABLE `playlists` ADD COLUMN `is_thumbnail_permanent` " | ||||||
|  |                     + "INTEGER NOT NULL DEFAULT 0"); | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     private Migrations() { |     private Migrations() { | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ public class PlaylistEntity { | |||||||
|     public static final String PLAYLIST_ID = "uid"; |     public static final String PLAYLIST_ID = "uid"; | ||||||
|     public static final String PLAYLIST_NAME = "name"; |     public static final String PLAYLIST_NAME = "name"; | ||||||
|     public static final String PLAYLIST_THUMBNAIL_URL = "thumbnail_url"; |     public static final String PLAYLIST_THUMBNAIL_URL = "thumbnail_url"; | ||||||
|     public static final String PLAYLIST_THUMBNAIL_PERMANENT = "isThumbnailSet"; |     public static final String PLAYLIST_THUMBNAIL_PERMANENT = "is_thumbnail_permanent"; | ||||||
|  |  | ||||||
|     @PrimaryKey(autoGenerate = true) |     @PrimaryKey(autoGenerate = true) | ||||||
|     @ColumnInfo(name = PLAYLIST_ID) |     @ColumnInfo(name = PLAYLIST_ID) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jared Fantaye
					Jared Fantaye