Migrate database (1)
This commit is contained in:
13
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Album.kt
Normal file
13
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Album.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Album(
|
||||
@PrimaryKey val id: String,
|
||||
val title: String,
|
||||
val thumbnailUrl: String?,
|
||||
val year: String?,
|
||||
val authorsText: String?
|
||||
)
|
||||
12
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Artist.kt
Normal file
12
app/src/main/kotlin/it/vfsfitvnm/vimusic/models/Artist.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Artist(
|
||||
@PrimaryKey val id: String,
|
||||
val name: String,
|
||||
val thumbnailUrl: String?,
|
||||
val info: String?
|
||||
)
|
||||
@@ -0,0 +1,26 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Junction
|
||||
import androidx.room.Relation
|
||||
|
||||
|
||||
data class DetailedSong(
|
||||
@Embedded val song: Song,
|
||||
@Relation(
|
||||
entity = Album::class,
|
||||
parentColumn = "albumId",
|
||||
entityColumn = "id"
|
||||
) val album: Album?,
|
||||
@Relation(
|
||||
entity = Artist::class,
|
||||
parentColumn = "id",
|
||||
entityColumn = "id",
|
||||
associateBy = Junction(
|
||||
value = SongArtistMap::class,
|
||||
parentColumn = "songId",
|
||||
entityColumn = "artistId"
|
||||
)
|
||||
)
|
||||
val artists: List<Artist>?
|
||||
)
|
||||
@@ -7,7 +7,8 @@ import androidx.room.*
|
||||
data class Song(
|
||||
@PrimaryKey val id: String,
|
||||
val title: String,
|
||||
val albumInfoId: Long?,
|
||||
val albumId: String?,
|
||||
val artistsText: String? = null,
|
||||
val durationText: String,
|
||||
val thumbnailUrl: String?,
|
||||
val lyrics: String? = null,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package it.vfsfitvnm.vimusic.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
|
||||
|
||||
@Entity(
|
||||
primaryKeys = ["songId", "artistId"],
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = Song::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["songId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
),
|
||||
ForeignKey(
|
||||
entity = Artist::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["artistId"],
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
]
|
||||
)
|
||||
data class SongArtistMap(
|
||||
@ColumnInfo(index = true) val songId: String,
|
||||
@ColumnInfo(index = true) val artistId: String
|
||||
)
|
||||
@@ -8,7 +8,7 @@ open class SongWithInfo(
|
||||
@Embedded val song: Song,
|
||||
@Relation(
|
||||
entity = Info::class,
|
||||
parentColumn = "albumInfoId",
|
||||
parentColumn = "albumId",
|
||||
entityColumn = "id"
|
||||
) val album: Info?,
|
||||
@Relation(
|
||||
|
||||
Reference in New Issue
Block a user