From 3fee37ac198cb095a0f255f8bf3d2cea82f125f6 Mon Sep 17 00:00:00 2001 From: dkanada Date: Thu, 27 May 2021 12:05:00 +0900 Subject: [PATCH] update room version and fix annotation error --- app/build.gradle | 4 ++-- app/src/main/java/com/dkanada/gramophone/App.java | 1 + .../dkanada/gramophone/database/JellyDatabase.java | 14 +++++++++++++- .../com/dkanada/gramophone/database/QueueSong.java | 14 ++++++++------ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cc98bb5e..101658ce 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -89,8 +89,8 @@ dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' - annotationProcessor 'androidx.room:room-compiler:2.2.6' - implementation 'androidx.room:room-runtime:2.2.6' + annotationProcessor 'androidx.room:room-compiler:2.3.0' + implementation 'androidx.room:room-runtime:2.3.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' implementation 'com.github.bumptech.glide:annotations:4.11.0' diff --git a/app/src/main/java/com/dkanada/gramophone/App.java b/app/src/main/java/com/dkanada/gramophone/App.java index f97f82ef..99c4f197 100644 --- a/app/src/main/java/com/dkanada/gramophone/App.java +++ b/app/src/main/java/com/dkanada/gramophone/App.java @@ -62,6 +62,7 @@ public class App extends Application { .addMigrations(JellyDatabase.Migration3) .addMigrations(JellyDatabase.Migration4) .addMigrations(JellyDatabase.Migration5) + .addMigrations(JellyDatabase.Migration6) .build(); } diff --git a/app/src/main/java/com/dkanada/gramophone/database/JellyDatabase.java b/app/src/main/java/com/dkanada/gramophone/database/JellyDatabase.java index 71ac7487..7d70f3ef 100644 --- a/app/src/main/java/com/dkanada/gramophone/database/JellyDatabase.java +++ b/app/src/main/java/com/dkanada/gramophone/database/JellyDatabase.java @@ -15,7 +15,7 @@ import com.dkanada.gramophone.model.User; QueueSong.class, User.class }, - version = 5, + version = 6, exportSchema = false ) public abstract class JellyDatabase extends RoomDatabase { @@ -64,4 +64,16 @@ public abstract class JellyDatabase extends RoomDatabase { + "cache INTEGER NOT NULL DEFAULT 1)"); } }; + + public static final Migration Migration6 = new Migration(5, 6) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("DROP TABLE queueSongs"); + + database.execSQL("CREATE TABLE queueSongs ('index' INTEGER NOT NULL," + + "queue INTEGER NOT NULL, songId TEXT," + + "PRIMARY KEY ('index', queue)," + + "FOREIGN KEY (songId) REFERENCES songs(id) ON DELETE CASCADE)"); + } + }; } diff --git a/app/src/main/java/com/dkanada/gramophone/database/QueueSong.java b/app/src/main/java/com/dkanada/gramophone/database/QueueSong.java index 8cd66f0b..27483bd9 100644 --- a/app/src/main/java/com/dkanada/gramophone/database/QueueSong.java +++ b/app/src/main/java/com/dkanada/gramophone/database/QueueSong.java @@ -10,6 +10,14 @@ import com.dkanada.gramophone.model.Song; primaryKeys = { "index", "queue" + }, + foreignKeys = { + @ForeignKey( + entity = Song.class, + parentColumns = {"id"}, + childColumns = {"songId"}, + onDelete = ForeignKey.CASCADE + ) } ) public class QueueSong { @@ -17,12 +25,6 @@ public class QueueSong { public int queue; - @ForeignKey( - entity = Song.class, - parentColumns = {"id"}, - childColumns = {"songId"}, - onDelete = ForeignKey.CASCADE - ) public String songId; public QueueSong(String songId, int index, int queue) {