diff --git a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java index 5ddb7a80b2..79b5236162 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -38,6 +38,10 @@ public class BgReading implements DataPointWithLabelInterface { public String direction; @DatabaseField public double raw; + @DatabaseField + public boolean filtered; + @DatabaseField + public String sourcePlugin; @DatabaseField public int source = Source.NONE; @@ -120,19 +124,11 @@ public class BgReading implements DataPointWithLabelInterface { ", value=" + value + ", direction=" + direction + ", raw=" + raw + + ", filtered=" + filtered + + ", sourcePlugin=" + sourcePlugin + '}'; } - public boolean isDataChanging(BgReading other) { - if (date != other.date) { - log.error("Comparing different"); - return false; - } - if (value != other.value) - return true; - return false; - } - public boolean isEqual(BgReading other) { if (date != other.date) { log.error("Comparing different"); @@ -158,6 +154,8 @@ public class BgReading implements DataPointWithLabelInterface { raw = other.raw; direction = other.direction; _id = other._id; + sourcePlugin = other.sourcePlugin; + filtered = other.filtered; } // ------------------ DataPointWithLabelInterface ------------------ diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 1c6cfddaf5..12b8b46a85 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -117,12 +117,27 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class); TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class); TableUtils.createTableIfNotExists(connectionSource, TDD.class); + + // soft migration without changing DB version + createRowIfNotExists(getDaoBgReadings(), DatabaseHelper.DATABASE_BGREADINGS, + "filtered", "integer"); + createRowIfNotExists(getDaoBgReadings(), DatabaseHelper.DATABASE_BGREADINGS, + "sourcePlugin", "integer"); + } catch (SQLException e) { log.error("Can't create database", e); throw new RuntimeException(e); } } + private void createRowIfNotExists(Dao dao, String table, String name, String type) { + try { + dao.executeRaw("ALTER TABLE `" + table + "` ADD CoLUMN `" + name + " " + type); + } catch (SQLException e) { + // row already exists + } + } + @Override public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { try {