1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-23 00:33:09 +02:00

Change order of columns in index

By putting userId first we avoid a compiler warnings an most likely
make better use of the index.
This commit is contained in:
Erik Johansson
2018-01-27 20:56:12 +01:00
parent bdeefc2d69
commit 763559e3a1
3 changed files with 9 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
"formatVersion": 1, "formatVersion": 1,
"database": { "database": {
"version": 2, "version": 2,
"identityHash": "166a2a83c723c4117edaf1d107ac5194", "identityHash": "29790d4babbe129963d2c9282393c2d2",
"entities": [ "entities": [
{ {
"tableName": "scaleMeasurements", "tableName": "scaleMeasurements",
@@ -95,13 +95,13 @@
}, },
"indices": [ "indices": [
{ {
"name": "index_scaleMeasurements_datetime_userId", "name": "index_scaleMeasurements_userId_datetime",
"unique": true, "unique": true,
"columnNames": [ "columnNames": [
"datetime", "userId",
"userId" "datetime"
], ],
"createSql": "CREATE UNIQUE INDEX `index_scaleMeasurements_datetime_userId` ON `${TABLE_NAME}` (`datetime`, `userId`)" "createSql": "CREATE UNIQUE INDEX `index_scaleMeasurements_userId_datetime` ON `${TABLE_NAME}` (`userId`, `datetime`)"
} }
], ],
"foreignKeys": [ "foreignKeys": [
@@ -189,7 +189,7 @@
], ],
"setupQueries": [ "setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", "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, \"166a2a83c723c4117edaf1d107ac5194\")" "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"29790d4babbe129963d2c9282393c2d2\")"
] ]
} }
} }

View File

@@ -54,8 +54,8 @@ public abstract class AppDatabase extends RoomDatabase {
+ " ON UPDATE NO ACTION ON DELETE CASCADE)"); + " ON UPDATE NO ACTION ON DELETE CASCADE)");
// Create new index on datetime + userId // Create new index on datetime + userId
database.execSQL("CREATE UNIQUE INDEX index_scaleMeasurements_datetime_userId" database.execSQL("CREATE UNIQUE INDEX index_scaleMeasurements_userId_datetime"
+ " ON scaleMeasurements (datetime, userId)"); + " ON scaleMeasurements (userId, datetime)");
// Copy data from the old table, ignoring those with invalid userId (if any) // Copy data from the old table, ignoring those with invalid userId (if any)
database.execSQL("INSERT INTO scaleMeasurements" database.execSQL("INSERT INTO scaleMeasurements"

View File

@@ -28,7 +28,7 @@ import com.j256.simplecsv.common.CsvColumn;
import java.util.Date; import java.util.Date;
@Entity(tableName = "scaleMeasurements", @Entity(tableName = "scaleMeasurements",
indices = {@Index(value = {"datetime", "userId"}, unique = true)}, indices = {@Index(value = {"userId", "datetime"}, unique = true)},
foreignKeys = @ForeignKey( foreignKeys = @ForeignKey(
entity = ScaleUser.class, entity = ScaleUser.class,
parentColumns = "id", parentColumns = "id",