mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-03 08:52:58 +01:00
Some migration fixes
especially: add unique index on samples using timestamp and device id (since composite primary keys are not fully supported yet)
This commit is contained in:
parent
04c8a17d6e
commit
0596c80381
@ -17,6 +17,7 @@ package nodomain.freeyourgadget.gadgetbridge.daogen;
|
|||||||
|
|
||||||
import de.greenrobot.daogenerator.DaoGenerator;
|
import de.greenrobot.daogenerator.DaoGenerator;
|
||||||
import de.greenrobot.daogenerator.Entity;
|
import de.greenrobot.daogenerator.Entity;
|
||||||
|
import de.greenrobot.daogenerator.Index;
|
||||||
import de.greenrobot.daogenerator.Property;
|
import de.greenrobot.daogenerator.Property;
|
||||||
import de.greenrobot.daogenerator.Schema;
|
import de.greenrobot.daogenerator.Schema;
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ public class GBDaoGenerator {
|
|||||||
private static final String VALID_BY_DATE = MODEL_PACKAGE + ".ValidByDate";
|
private static final String VALID_BY_DATE = MODEL_PACKAGE + ".ValidByDate";
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Schema schema = new Schema(10, MAIN_PACKAGE + ".entities");
|
Schema schema = new Schema(7, MAIN_PACKAGE + ".entities");
|
||||||
|
|
||||||
addActivityDescription(schema);
|
addActivityDescription(schema);
|
||||||
|
|
||||||
@ -157,7 +158,7 @@ public class GBDaoGenerator {
|
|||||||
"intensity, are device specific. Normalized values can be retrieved through the\n" +
|
"intensity, are device specific. Normalized values can be retrieved through the\n" +
|
||||||
"corresponding {@link SampleProvider}.");
|
"corresponding {@link SampleProvider}.");
|
||||||
activitySample.addIdProperty();
|
activitySample.addIdProperty();
|
||||||
activitySample.addIntProperty("timestamp").notNull();
|
Property timestamp = activitySample.addIntProperty("timestamp").notNull().getProperty();
|
||||||
activitySample.addIntProperty("rawIntensity").notNull();
|
activitySample.addIntProperty("rawIntensity").notNull();
|
||||||
activitySample.addIntProperty("steps").notNull();
|
activitySample.addIntProperty("steps").notNull();
|
||||||
activitySample.addIntProperty("rawKind").notNull();
|
activitySample.addIntProperty("rawKind").notNull();
|
||||||
@ -165,6 +166,12 @@ public class GBDaoGenerator {
|
|||||||
activitySample.addToOne(user, userId);
|
activitySample.addToOne(user, userId);
|
||||||
Property deviceId = activitySample.addLongProperty("deviceId").getProperty();
|
Property deviceId = activitySample.addLongProperty("deviceId").getProperty();
|
||||||
activitySample.addToOne(device, deviceId);
|
activitySample.addToOne(device, deviceId);
|
||||||
|
|
||||||
|
Index indexUnique = new Index();
|
||||||
|
indexUnique.addProperty(timestamp);
|
||||||
|
indexUnique.addProperty(deviceId);
|
||||||
|
indexUnique.makeUnique();
|
||||||
|
activitySample.addIndex(indexUnique);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Entity addEntity(Schema schema, String className) {
|
private static Entity addEntity(Schema schema, String className) {
|
||||||
|
@ -157,7 +157,7 @@ public class GBApplication extends Application {
|
|||||||
|
|
||||||
static void setupDatabase(Context context) {
|
static void setupDatabase(Context context) {
|
||||||
// DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "test-db", null);
|
// DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "test-db", null);
|
||||||
DBOpenHelper helper = new DBOpenHelper(context, "test-db2", null);
|
DBOpenHelper helper = new DBOpenHelper(context, "test-db4", null);
|
||||||
SQLiteDatabase db = helper.getWritableDatabase();
|
SQLiteDatabase db = helper.getWritableDatabase();
|
||||||
DaoMaster daoMaster = new DaoMaster(db);
|
DaoMaster daoMaster = new DaoMaster(db);
|
||||||
if (lockHandler == null) {
|
if (lockHandler == null) {
|
||||||
|
@ -4,7 +4,6 @@ import android.Manifest;
|
|||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.bluetooth.BluetoothDevice;
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@ -327,7 +326,6 @@ public class ControlCenter extends GBActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||||
unregisterReceiver(mReceiver);
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +383,7 @@ public class DBHelper {
|
|||||||
}
|
}
|
||||||
newSamples.add(newSample);
|
newSamples.add(newSample);
|
||||||
}
|
}
|
||||||
sampleProvider.getSampleDao().insertInTx(newSamples, true);
|
sampleProvider.getSampleDao().insertOrReplaceInTx(newSamples, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user