kopia lustrzana https://github.com/rt-bishop/Look4Sat
Added database migration and schema export, fixed crash
rodzic
94751519ac
commit
4bf2e6c768
|
@ -16,6 +16,12 @@ android {
|
|||
targetSdkVersion 31
|
||||
versionCode 253
|
||||
versionName "2.5.3"
|
||||
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 2,
|
||||
"identityHash": "825f728737780384e51a6a73221288c4",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "entries",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`tle` TEXT NOT NULL, `catNum` INTEGER NOT NULL, `name` TEXT NOT NULL, `isSelected` INTEGER NOT NULL, PRIMARY KEY(`catNum`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "tle",
|
||||
"columnName": "tle",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "catNum",
|
||||
"columnName": "catNum",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isSelected",
|
||||
"columnName": "isSelected",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"catNum"
|
||||
],
|
||||
"autoGenerate": false
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "transmitters",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uuid` TEXT NOT NULL, `info` TEXT NOT NULL, `isAlive` INTEGER NOT NULL, `downlink` INTEGER, `uplink` INTEGER, `mode` TEXT, `isInverted` INTEGER NOT NULL, `catNum` INTEGER, PRIMARY KEY(`uuid`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "uuid",
|
||||
"columnName": "uuid",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "info",
|
||||
"columnName": "info",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isAlive",
|
||||
"columnName": "isAlive",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "downlink",
|
||||
"columnName": "downlink",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "uplink",
|
||||
"columnName": "uplink",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "mode",
|
||||
"columnName": "mode",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "isInverted",
|
||||
"columnName": "isInverted",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "catNum",
|
||||
"columnName": "catNum",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": false
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"uuid"
|
||||
],
|
||||
"autoGenerate": false
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '825f728737780384e51a6a73221288c4')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -20,12 +20,23 @@ package com.rtbishop.look4sat.framework.db
|
|||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.rtbishop.look4sat.framework.model.SatEntry
|
||||
import com.rtbishop.look4sat.framework.model.Transmitter
|
||||
|
||||
@Database(entities = [SatEntry::class, Transmitter::class], version = 1, exportSchema = false)
|
||||
@Database(entities = [SatEntry::class, Transmitter::class], version = 2, exportSchema = true)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class SatelliteDb : RoomDatabase() {
|
||||
|
||||
abstract fun satelliteDao(): SatelliteDao
|
||||
}
|
||||
|
||||
val MIGRATION_1_2 = object : Migration(1, 2) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("CREATE TABLE trans_backup (uuid TEXT NOT NULL, info TEXT NOT NULL, isAlive INTEGER NOT NULL, downlink INTEGER, uplink INTEGER, mode TEXT, isInverted INTEGER NOT NULL, catNum INTEGER, PRIMARY KEY(uuid))")
|
||||
database.execSQL("INSERT INTO trans_backup (uuid, info, isAlive, downlink, uplink, mode, isInverted, catNum) SELECT uuid, info, isAlive, downlink, uplink, mode, isInverted, catNum FROM transmitters")
|
||||
database.execSQL("DROP TABLE transmitters")
|
||||
database.execSQL("ALTER TABLE trans_backup RENAME TO transmitters")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,5 +30,5 @@ data class Transmitter(
|
|||
@field:Json(name = "uplink_low") var uplink: Long?,
|
||||
@field:Json(name = "mode") val mode: String?,
|
||||
@field:Json(name = "invert") val isInverted: Boolean,
|
||||
@field:Json(name = "norad_cat_id") val catNum: Int
|
||||
@field:Json(name = "norad_cat_id") val catNum: Int?
|
||||
)
|
||||
|
|
|
@ -26,10 +26,7 @@ import com.rtbishop.look4sat.domain.Predictor
|
|||
import com.rtbishop.look4sat.framework.PreferencesProvider
|
||||
import com.rtbishop.look4sat.framework.api.RemoteSource
|
||||
import com.rtbishop.look4sat.framework.api.SatelliteService
|
||||
import com.rtbishop.look4sat.framework.db.Converters
|
||||
import com.rtbishop.look4sat.framework.db.LocalSource
|
||||
import com.rtbishop.look4sat.framework.db.SatelliteDao
|
||||
import com.rtbishop.look4sat.framework.db.SatelliteDb
|
||||
import com.rtbishop.look4sat.framework.db.*
|
||||
import com.squareup.moshi.Moshi
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
|
@ -92,7 +89,8 @@ object SatelliteDataModule {
|
|||
@Provides
|
||||
fun provideSatelliteDb(@ApplicationContext context: Context, moshi: Moshi): SatelliteDb {
|
||||
Converters.initialize(moshi)
|
||||
return Room.databaseBuilder(context, SatelliteDb::class.java, "SatelliteDb").build()
|
||||
return Room.databaseBuilder(context, SatelliteDb::class.java, "SatelliteDb")
|
||||
.addMigrations(MIGRATION_1_2).build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -25,5 +25,5 @@ data class Transmitter(
|
|||
var uplink: Long?,
|
||||
val mode: String?,
|
||||
val isInverted: Boolean,
|
||||
val catNum: Int
|
||||
val catNum: Int?
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue