This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
232 additions
and
40 deletions.
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
app/schemas/com.sanmer.geomag.database.AppDatabase/2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 2, | ||
"identityHash": "52106f15f8adce755d04751dca2c035b", | ||
"entities": [ | ||
{ | ||
"tableName": "records", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` REAL NOT NULL, `model` TEXT NOT NULL, `time` TEXT NOT NULL, `altitude` REAL NOT NULL, `latitude` REAL NOT NULL, `longitude` REAL NOT NULL, `declination` REAL NOT NULL, `declinationSV` REAL NOT NULL, `inclination` REAL NOT NULL, `inclinationSV` REAL NOT NULL, `horizontalIntensity` REAL NOT NULL, `horizontalSV` REAL NOT NULL, `northComponent` REAL NOT NULL, `northSV` REAL NOT NULL, `eastComponent` REAL NOT NULL, `eastSV` REAL NOT NULL, `verticalComponent` REAL NOT NULL, `verticalSV` REAL NOT NULL, `totalIntensity` REAL NOT NULL, `totalSV` REAL NOT NULL, PRIMARY KEY(`id`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "model", | ||
"columnName": "model", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "time", | ||
"columnName": "time", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "altitude", | ||
"columnName": "altitude", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "latitude", | ||
"columnName": "latitude", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "longitude", | ||
"columnName": "longitude", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.declination", | ||
"columnName": "declination", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.declinationSV", | ||
"columnName": "declinationSV", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.inclination", | ||
"columnName": "inclination", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.inclinationSV", | ||
"columnName": "inclinationSV", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.horizontalIntensity", | ||
"columnName": "horizontalIntensity", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.horizontalSV", | ||
"columnName": "horizontalSV", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.northComponent", | ||
"columnName": "northComponent", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.northSV", | ||
"columnName": "northSV", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.eastComponent", | ||
"columnName": "eastComponent", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.eastSV", | ||
"columnName": "eastSV", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.verticalComponent", | ||
"columnName": "verticalComponent", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.verticalSV", | ||
"columnName": "verticalSV", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.totalIntensity", | ||
"columnName": "totalIntensity", | ||
"affinity": "REAL", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "values.totalSV", | ||
"columnName": "totalSV", | ||
"affinity": "REAL", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": false, | ||
"columnNames": [ | ||
"id" | ||
] | ||
}, | ||
"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, '52106f15f8adce755d04751dca2c035b')" | ||
] | ||
} | ||
} |
58 changes: 57 additions & 1 deletion
58
app/src/main/kotlin/com/sanmer/geomag/database/AppDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,67 @@ | ||
package com.sanmer.geomag.database | ||
|
||
import android.content.Context | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import androidx.room.migration.Migration | ||
import com.sanmer.geomag.database.dao.RecordDao | ||
import com.sanmer.geomag.database.entity.RecordEntity | ||
|
||
@Database(entities = [RecordEntity::class], version = 1) | ||
@Database(entities = [RecordEntity::class], version = 2) | ||
abstract class AppDatabase : RoomDatabase() { | ||
abstract fun recordDao(): RecordDao | ||
|
||
companion object { | ||
fun build(context: Context): AppDatabase { | ||
return Room.databaseBuilder(context, | ||
AppDatabase::class.java, "geomag") | ||
.addMigrations( | ||
MIGRATION_1_2 | ||
) | ||
.build() | ||
} | ||
|
||
private val MIGRATION_1_2 = Migration(1, 2) { | ||
it.execSQL("CREATE TABLE IF NOT EXISTS records_new (" + | ||
"id REAL NOT NULL, " + | ||
"model TEXT NOT NULL, " + | ||
"time TEXT NOT NULL, " + | ||
"altitude REAL NOT NULL, " + | ||
"latitude REAL NOT NULL, " + | ||
"longitude REAL NOT NULL, " + | ||
"declination REAL NOT NULL, " + | ||
"declinationSV REAL NOT NULL, " + | ||
"inclination REAL NOT NULL, " + | ||
"inclinationSV REAL NOT NULL, " + | ||
"horizontalIntensity REAL NOT NULL, " + | ||
"horizontalSV REAL NOT NULL, " + | ||
"northComponent REAL NOT NULL, " + | ||
"northSV REAL NOT NULL, " + | ||
"eastComponent REAL NOT NULL, " + | ||
"eastSV REAL NOT NULL, " + | ||
"verticalComponent REAL NOT NULL, " + | ||
"verticalSV REAL NOT NULL, " + | ||
"totalIntensity REAL NOT NULL, " + | ||
"totalSV REAL NOT NULL, " + | ||
"PRIMARY KEY(id))") | ||
|
||
it.execSQL("INSERT INTO records_new (" + | ||
"id, model, time, altitude, latitude, longitude, " + | ||
"declination, declinationSV, inclination, inclinationSV, " + | ||
"horizontalIntensity, horizontalSV, northComponent, northSV, " + | ||
"eastComponent, eastSV, verticalComponent, verticalSV, " + | ||
"totalIntensity, totalSV) " + | ||
"SELECT " + | ||
"id, model, time, altitude, latitude, longitude, " + | ||
"declination, declination_sv, inclination, inclination_sv, " + | ||
"horizontal_intensity, horizontal_sv, north_component, north_sv, " + | ||
"east_component, east_sv, vertical_component, vertical_sv, " + | ||
"total_intensity, total_sv " + | ||
"FROM records") | ||
|
||
it.execSQL("DROP TABLE records") | ||
it.execSQL("ALTER TABLE records_new RENAME TO records") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters