57 lines
1.9 KiB
Kotlin
57 lines
1.9 KiB
Kotlin
package com.radiola.data.local
|
|
|
|
import androidx.room.Database
|
|
import androidx.room.RoomDatabase
|
|
import androidx.room.migration.Migration
|
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
|
import com.radiola.data.local.dao.RecordingDao
|
|
import com.radiola.data.local.dao.StationDao
|
|
import com.radiola.data.local.dao.TagDao
|
|
import com.radiola.data.local.dao.TrackHistoryDao
|
|
import com.radiola.data.local.entity.RecordingEntity
|
|
import com.radiola.data.local.entity.StationEntity
|
|
import com.radiola.data.local.entity.TagEntity
|
|
import com.radiola.data.local.entity.TrackHistoryEntity
|
|
|
|
val MIGRATION_1_2 = object : Migration(1, 2) {
|
|
override fun migrate(database: SupportSQLiteDatabase) {
|
|
database.execSQL("CREATE TABLE IF NOT EXISTS tags (name TEXT PRIMARY KEY NOT NULL)")
|
|
}
|
|
}
|
|
|
|
val MIGRATION_2_3 = object : Migration(2, 3) {
|
|
override fun migrate(database: SupportSQLiteDatabase) {
|
|
database.execSQL("ALTER TABLE stations ADD COLUMN source TEXT NOT NULL DEFAULT 'record'")
|
|
}
|
|
}
|
|
|
|
val MIGRATION_3_4 = object : Migration(3, 4) {
|
|
override fun migrate(database: SupportSQLiteDatabase) {
|
|
database.execSQL(
|
|
"""
|
|
CREATE TABLE IF NOT EXISTS recordings (
|
|
id INTEGER PRIMARY KEY NOT NULL,
|
|
stationName TEXT NOT NULL,
|
|
stationId INTEGER NOT NULL,
|
|
filePath TEXT NOT NULL,
|
|
startTime INTEGER NOT NULL,
|
|
endTime INTEGER,
|
|
trackName TEXT,
|
|
duration INTEGER
|
|
)
|
|
""".trimIndent()
|
|
)
|
|
}
|
|
}
|
|
|
|
@Database(
|
|
entities = [StationEntity::class, TrackHistoryEntity::class, TagEntity::class, RecordingEntity::class],
|
|
version = 4
|
|
)
|
|
abstract class AppDatabase : RoomDatabase() {
|
|
abstract fun stationDao(): StationDao
|
|
abstract fun trackHistoryDao(): TrackHistoryDao
|
|
abstract fun tagDao(): TagDao
|
|
abstract fun recordingDao(): RecordingDao
|
|
}
|