Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

#302 #388

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

#302 #388

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions app/src/androidTest/java/de/dreier/mytargets/app/MigrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,128 @@ class MigrationTest : InstrumentedTestBase() {
assertThat(db.endDAO().loadEnds(rounds[0].id)).hasSize(6)
assertThat(db.endDAO().loadEnds(rounds[1].id)).hasSize(6)
}


private fun insertTrainingDataForVersion26(db: SupportSQLiteDatabase) {
db.execSQL("INSERT INTO `RoundTemplate` (id,standardRoundId,`index`,shotsPerEnd,endCount,distance,targetId,targetScoringStyleIndex,targetDiameter) VALUES (13,11,0,6,5,'20.0 yd',0,0,'40.0 cm');")
db.execSQL("INSERT INTO `StandardRound` (id,club,name) VALUES (11,4,'Bray I');")
db.execSQL("INSERT INTO `Training` (id,title,date,standardRoundId,bowId,arrowId,arrowNumbering,comment,archerSignatureId,witnessSignatureId,indoor,weather,windSpeed,windDirection,location,reachedPoints,totalPoints,shotCount) VALUES (1,'Training','2019-08-27',11,NULL,NULL,0,'',NULL,NULL,0,0,0,0,'',178,300,30);")
db.execSQL("INSERT INTO `Round` (id,trainingId,`index`,shotsPerEnd,maxEndCount,distance,comment,targetId,targetScoringStyleIndex,targetDiameter,reachedPoints,totalPoints,shotCount) VALUES (1,1,0,6,5,'20.0 yd','',0,0,'40.0 cm',178,300,30);")

db.execSQL("INSERT INTO `End` (id,`index`,roundId,exact,saveTime,comment,reachedPoints,totalPoints,shotCount) VALUES (1,0,1,1,'21:05:52.528','test',54,60,6);")
db.execSQL("INSERT INTO `End` (id,`index`,roundId,exact,saveTime,comment,reachedPoints,totalPoints,shotCount) VALUES (2,1,1,1,'21:06:02.347','',45,60,6);")
db.execSQL("INSERT INTO `End` (id,`index`,roundId,exact,saveTime,comment,reachedPoints,totalPoints,shotCount) VALUES (3,2,1,1,'21:06:08.17','',18,60,6);")
db.execSQL("INSERT INTO `End` (id,`index`,roundId,exact,saveTime,comment,reachedPoints,totalPoints,shotCount) VALUES (4,3,1,1,'21:06:15.663','',1,60,6);")
db.execSQL("INSERT INTO `End` (id,`index`,roundId,exact,saveTime,comment,reachedPoints,totalPoints,shotCount) VALUES (5,4,1,1,'21:06:25.499','',60,60,6);")

db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (1,0,1,0.0909451246261597,0.140448212623596,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (2,1,1,0.158708214759827,-0.0522582530975342,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (3,2,1,-0.130176305770874,0.0333890914916992,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (4,3,1,-0.00534975528717041,-0.170023441314697,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (5,4,1,0.155141711235046,0.0512322187423706,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (6,5,1,-0.0802456140518188,0.176134705543518,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (7,0,2,0.169407725334167,0.21182119846344,3,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (8,1,2,-0.0445809364318848,0.254644751548767,3,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (9,2,2,-0.287101149559021,0.101193308830261,3,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (10,3,2,-0.172973990440369,-0.155748844146729,3,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (11,4,2,0.183673501014709,-0.380573153495789,5,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (12,5,2,0.408361554145813,-0.0593955516815186,-2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (13,0,3,0.536754488945007,0.354566693305969,7,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (14,1,3,0.394095540046692,0.536567568778992,7,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (15,2,3,-0.226471185684204,0.679313063621521,8,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (16,3,3,-0.825638949871063,-0.14147424697876,9,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (17,4,3,-0.415494322776794,-0.605397462844849,8,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (18,5,3,0.793540835380554,-0.209278464317322,9,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (19,0,4,0.668714046478271,0.918412089347839,-1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (20,1,4,0.597384691238403,0.886294007301331,-1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (21,2,4,0.725777745246887,0.750685811042786,-1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (22,3,4,0.839905142784119,-0.887320160865784,-1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (23,4,4,0.458292126655579,-1.00508534908295,-1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (24,5,4,0.0445809364318848,-0.915869355201721,10,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (25,0,5,-0.0338814258575439,-0.0843760967254639,1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (26,1,5,-0.0267485380172729,-0.00943446159362793,0,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (27,2,5,-0.00178313255310059,0.0101931095123291,0,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (28,3,5,-0.0160490274429321,-0.0377378463745117,0,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (29,4,5,0.0124826431274414,-0.0389565229415894,0,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (30,5,5,0.0392313003540039,0.00840866565704346,0,NULL);")


db.execSQL("INSERT INTO `RoundTemplate` (id,standardRoundId,`index`,shotsPerEnd,endCount,distance,targetId,targetScoringStyleIndex,targetDiameter) VALUES (14,12,0,6,5,'25.0 yd',0,0,'60.0 cm');")
db.execSQL("INSERT INTO `StandardRound` (id,club,name) VALUES (12,4,'Bray II');")
db.execSQL("INSERT INTO `Training` (id,title,date,standardRoundId,bowId,arrowId,arrowNumbering,comment,archerSignatureId,witnessSignatureId,indoor,weather,windSpeed,windDirection,location,reachedPoints,totalPoints,shotCount) VALUES (2,'Training','2019-08-27',12,NULL,NULL,0,'',NULL,NULL,0,0,0,0,'',178,300,30);")
db.execSQL("INSERT INTO `Round` (id,trainingId,`index`,shotsPerEnd,maxEndCount,distance,comment,targetId,targetScoringStyleIndex,targetDiameter,reachedPoints,totalPoints,shotCount) VALUES (2,2,0,6,5,'20.0 yd','',0,0,'40.0 cm',178,300,30);")

db.execSQL("INSERT INTO `End` (id,`index`,roundId,exact,saveTime,comment,reachedPoints,totalPoints,shotCount) VALUES (6,0,2,1,'21:05:52.528','test',54,60,6);")
db.execSQL("INSERT INTO `End` (id,`index`,roundId,exact,saveTime,comment,reachedPoints,totalPoints,shotCount) VALUES (7,1,2,1,'21:06:02.347','',45,60,6);")
db.execSQL("INSERT INTO `End` (id,`index`,roundId,exact,saveTime,comment,reachedPoints,totalPoints,shotCount) VALUES (8,2,2,1,'21:06:08.17','',18,60,6);")
db.execSQL("INSERT INTO `End` (id,`index`,roundId,exact,saveTime,comment,reachedPoints,totalPoints,shotCount) VALUES (9,3,2,1,'21:06:15.663','',1,60,6);")
db.execSQL("INSERT INTO `End` (id,`index`,roundId,exact,saveTime,comment,reachedPoints,totalPoints,shotCount) VALUES (10,4,2,1,'21:06:25.499','',60,60,6);")

db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (31,0,6,0.0909451246261597,0.140448212623596,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (32,1,6,0.158708214759827,-0.0522582530975342,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (33,2,6,-0.130176305770874,0.0333890914916992,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (34,3,6,-0.00534975528717041,-0.170023441314697,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (35,4,6,0.155141711235046,0.0512322187423706,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (36,5,6,-0.0802456140518188,0.176134705543518,2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (37,0,7,0.169407725334167,0.21182119846344,3,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (38,1,7,-0.0445809364318848,0.254644751548767,3,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (39,2,7,-0.287101149559021,0.101193308830261,3,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (40,3,7,-0.172973990440369,-0.155748844146729,3,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (41,4,7,0.183673501014709,-0.380573153495789,5,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (42,5,7,0.408361554145813,-0.0593955516815186,-2,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (43,0,8,0.536754488945007,0.354566693305969,7,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (44,1,8,0.394095540046692,0.536567568778992,7,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (45,2,8,-0.226471185684204,0.679313063621521,8,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (46,3,8,-0.825638949871063,-0.14147424697876,9,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (47,4,8,-0.415494322776794,-0.605397462844849,8,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (48,5,8,0.793540835380554,-0.209278464317322,9,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (49,0,9,0.668714046478271,0.918412089347839,-1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (50,1,9,0.597384691238403,0.886294007301331,-1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (51,2,9,0.725777745246887,0.750685811042786,-1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (52,3,9,0.839905142784119,-0.887320160865784,-1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (53,4,9,0.458292126655579,-1.00508534908295,-1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (54,5,9,0.0445809364318848,-0.915869355201721,10,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (55,0,10,-0.0338814258575439,-0.0843760967254639,1,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (56,1,10,-0.0267485380172729,-0.00943446159362793,0,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (57,2,10,-0.00178313255310059,0.0101931095123291,0,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (58,3,10,-0.0160490274429321,-0.0377378463745117,0,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (59,4,10,0.0124826431274414,-0.0389565229415894,0,NULL);")
db.execSQL("INSERT INTO `Shot` (id,`index`,endId,x,y,scoringRing,arrowNumber) VALUES (60,5,10,0.0392313003540039,0.00840866565704346,0,NULL);")
}

@Test
fun upgrade26to27() {
val db = testHelper.createDatabase(TEST_DB_NAME, 26)
insertTrainingDataForVersion26(db)

val count = db.query("SELECT * FROM StandardRound").count
assertThat(count).isEqualTo(2)

db.close()

testHelper.runMigrationsAndValidate(
TEST_DB_NAME, 27,
true,
Migration27
)

val migratedDb = getMigratedRoomDatabase()

var ends = migratedDb.endDAO().loadEnds(1)
assertThat(ends.size).isEqualTo(10)
assertThat(ends.get(9).index).isEqualTo(9)
assertThat(ends.get(1).comment).isEqualTo("test")

var shots = migratedDb.endDAO().loadShots(20)
assertThat(shots.size).isEqualTo(3)
assertThat(shots.get(1).x).isEqualTo(0.0124826431274414.toFloat())
assertThat(shots.get(1).index).isEqualTo(1)

ends = migratedDb.endDAO().loadEnds(2)
assertThat(ends.size).isEqualTo(10)

shots = migratedDb.endDAO().loadShots(22)
assertThat(shots.size).isEqualTo(3)
assertThat(shots.get(2).y).isEqualTo(0.176134705543518.toFloat())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

package de.dreier.mytargets.app

import androidx.room.Room
import android.content.Context
import android.content.SharedPreferences
import android.content.res.Configuration
import androidx.multidex.MultiDex
import android.util.Log
import androidx.multidex.MultiDex
import androidx.room.Room
import androidx.room.RoomDatabase
import com.crashlytics.android.Crashlytics
import com.evernote.android.state.StateSaver
Expand Down Expand Up @@ -127,7 +127,7 @@ class ApplicationInstance : SharedApplicationInstance() {
Migration17, Migration18, Migration19,
Migration20, Migration21, Migration22,
Migration23, Migration24, Migration25,
Migration26
Migration26, Migration27
)
.build()
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/de/dreier/mytargets/base/db/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

package de.dreier.mytargets.base.db

import androidx.room.*
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import de.dreier.mytargets.base.db.dao.*
import de.dreier.mytargets.base.db.typeconverters.*
import de.dreier.mytargets.shared.models.db.*
Expand Down Expand Up @@ -50,7 +52,7 @@ abstract class AppDatabase : RoomDatabase() {
companion object {
const val DATABASE_FILE_NAME = "database.db"
const val DATABASE_IMPORT_FILE_NAME = "database"
const val VERSION = 26
const val VERSION = 27
}

abstract fun arrowDAO(): ArrowDAO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ object StandardRoundFactory {
build(
ARCHERY_GB, R.string.bray_i,
YARDS, CENTIMETER,
WAFull.ID, 0, 6, 20, 40, 5
WAFull.ID, 0, 3, 20, 40, 10
)
)
rounds.add(
build(
ARCHERY_GB, R.string.bray_ii,
YARDS, CENTIMETER,
WAFull.ID, 0, 6, 25, 60, 5
WAFull.ID, 0, 3, 25, 60, 10
)
)
rounds.add(
Expand Down
Loading