Migrate database (2)

This commit is contained in:
vfsfitvnm
2022-06-29 15:03:20 +02:00
parent a7bdda074b
commit 6f5bc02216
13 changed files with 545 additions and 145 deletions

View File

@@ -1,12 +0,0 @@
package it.vfsfitvnm.vimusic.models
import androidx.room.Entity
import androidx.room.PrimaryKey
// I know...
@Entity
data class Info(
@PrimaryKey(autoGenerate = true) val id: Long = 0,
val browseId: String?,
val text: String
)

View File

@@ -15,7 +15,7 @@ data class PlaylistWithSongs(
entityColumn = "songId"
)
)
val songs: List<SongWithInfo>
val songs: List<DetailedSong>
) {
companion object {
val Empty = PlaylistWithSongs(Playlist(-1, ""), emptyList())

View File

@@ -3,7 +3,16 @@ package it.vfsfitvnm.vimusic.models
import androidx.room.*
@Entity
@Entity(
// foreignKeys = [
// ForeignKey(
// entity = Album::class,
// parentColumns = ["id"],
// childColumns = ["albumId"],
// onDelete = ForeignKey.CASCADE
// ),
// ]
)
data class Song(
@PrimaryKey val id: String,
val title: String,

View File

@@ -1,28 +0,0 @@
package it.vfsfitvnm.vimusic.models
import androidx.compose.runtime.Immutable
import androidx.room.*
@Immutable
@Entity(
primaryKeys = ["songId", "authorInfoId"],
foreignKeys = [
ForeignKey(
entity = Song::class,
parentColumns = ["id"],
childColumns = ["songId"],
onDelete = ForeignKey.CASCADE
),
ForeignKey(
entity = Info::class,
parentColumns = ["id"],
childColumns = ["authorInfoId"],
onDelete = ForeignKey.CASCADE
)
]
)
data class SongWithAuthors(
val songId: String,
@ColumnInfo(index = true) val authorInfoId: Long
)

View File

@@ -1,25 +0,0 @@
package it.vfsfitvnm.vimusic.models
import androidx.room.Embedded
import androidx.room.Junction
import androidx.room.Relation
open class SongWithInfo(
@Embedded val song: Song,
@Relation(
entity = Info::class,
parentColumn = "albumId",
entityColumn = "id"
) val album: Info?,
@Relation(
entity = Info::class,
parentColumn = "id",
entityColumn = "id",
associateBy = Junction(
value = SongWithAuthors::class,
parentColumn = "songId",
entityColumn = "authorInfoId"
)
)
val authors: List<Info>?
)