File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
src/main/kotlin/database/migration Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 11package database.migration
22
3- import data.DataPoint
43import data.LatLng
54import database.entity.Zone
65import database.serialization.Json
@@ -13,15 +12,30 @@ object MigrateTo1 : Migration(null, 1) {
1312 migrateZones()
1413 }
1514
16- private fun migrateZones () {
15+ private fun Transaction. migrateZones () {
1716 Zone .all().forEach { zone ->
17+ // Move from latitude and longitude to point
1818 val lat = zone.latitude
1919 val lon = zone.longitude
2020 if (lat != null && lon != null ) zone.point = LatLng (lat, lon)
21+ zone.latitude = null
22+ zone.longitude = null
2123
22- zone.pointsString?.let { points ->
23- zone.points = Json .decodeFromString<List <DataPoint >>(points)
24+ // Move from pointsString to points
25+ val pointsString = zone.pointsString
26+ if (pointsString == " \u0000 " ) {
27+ zone.points = emptyList()
28+ } else if (! pointsString.isNullOrEmpty()) {
29+ // Points were saved sometimes in a wrong JSON format. Instead of arrays, they were objects in multiple lines.
30+ if (pointsString.startsWith(" {" )) {
31+ pointsString.split(' \n ' ).joinToString(" ," ) { it.trim() }.let {
32+ zone.points = Json .decodeFromString(" [$it ]" )
33+ }
34+ } else {
35+ zone.points = Json .decodeFromString(pointsString)
36+ }
2437 }
38+ zone.pointsString = null
2539 }
2640 }
2741}
You can’t perform that action at this time.
0 commit comments