Skip to content

Commit

Permalink
Merge pull request #65 from SUPLA/develop
Browse files Browse the repository at this point in the history
Improved database update procedure
  • Loading branch information
przemyslawzygmunt authored May 11, 2019
2 parents 53c5339 + 38b531b commit ec83ba9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
1 change: 0 additions & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "org.supla.android"
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
versionCode 51
versionName "2.3.0"
versionCode 52
versionName "2.3.1"

sourceSets.main {
jniLibs.srcDir 'src/main/libs'
Expand Down
36 changes: 20 additions & 16 deletions app/src/main/java/org/supla/android/db/DbHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,8 @@ private void upgradeToV4(SQLiteDatabase db) {
createLocationTable(db);
createChannelTable(db);
createChannelValueTable(db);
createChannelView(db);
createChannelGroupTable(db);
createChannelGroupRelationTable(db);
createChannelGroupValueView(db);

}

private void upgradeToV5(SQLiteDatabase db) {
Expand All @@ -609,7 +606,6 @@ private void upgradeToV6(SQLiteDatabase db) {
Trace.d(DbHelper.class.getName(), "upgradeToV6");

createElectricityMeterLogTable(db);
createElectricityMeterLogView(db);

execSQL(db, "ALTER TABLE " + SuplaContract.ChannelEntry.TABLE_NAME
+ " ADD COLUMN " + SuplaContract.ChannelEntry.COLUMN_NAME_DEVICEID
Expand Down Expand Up @@ -639,8 +635,6 @@ private void upgradeToV6(SQLiteDatabase db) {
+ " ADD COLUMN " + SuplaContract.LocationEntry.COLUMN_NAME_COLLAPSED
+ " INTEGER NOT NULL default 0");

execSQL(db, "DROP VIEW " + SuplaContract.ChannelViewEntry.VIEW_NAME);
createChannelView(db);
}

private void upgradeToV7(SQLiteDatabase db) {
Expand All @@ -651,21 +645,15 @@ private void upgradeToV7(SQLiteDatabase db) {
private void upgradeToV8(SQLiteDatabase db) {
Trace.d(DbHelper.class.getName(), "upgradeToV8");
createUserIconsTable(db);
execSQL(db, "DROP VIEW " + SuplaContract.ChannelViewEntry.VIEW_NAME);
createChannelView(db);
}

private void upgradeToV9(SQLiteDatabase db) {
Trace.d(DbHelper.class.getName(), "upgradeToV9");
execSQL(db, "DROP TABLE " + SuplaContract.ChannelValueEntry.TABLE_NAME);
execSQL(db, "DROP TABLE " + SuplaContract.ChannelExtendedValueEntry.TABLE_NAME);
execSQL(db, "DROP VIEW " + SuplaContract.ChannelViewEntry.VIEW_NAME);
execSQL(db, "DROP VIEW " + SuplaContract.ChannelGroupValueViewEntry.VIEW_NAME);

createChannelValueTable(db);
createChannelExtendedValueTable(db);
createChannelView(db);
createChannelGroupValueView(db);


createImpulseCounterLogTable(db);
createTemperatureLogTable(db);
Expand All @@ -676,19 +664,32 @@ private void upgradeToV10(SQLiteDatabase db) {
Trace.d(DbHelper.class.getName(), "upgradeToV10");
execSQL(db, "DROP TABLE " + SuplaContract.ImpulseCounterLogEntry.TABLE_NAME);
createImpulseCounterLogTable(db);
createImpulseCounterLogView(db);
}

private void upgradeToV11(SQLiteDatabase db) {
Trace.d(DbHelper.class.getName(), "upgradeToV11");
execSQL(db, "DROP VIEW " + SuplaContract.ImpulseCounterLogViewEntry.VIEW_NAME);
execSQL(db, "DROP VIEW " + SuplaContract.ElectricityMeterLogViewEntry.VIEW_NAME);

execSQL(db, "DROP TABLE " + SuplaContract.ElectricityMeterLogEntry.TABLE_NAME);
execSQL(db, "DROP TABLE " + SuplaContract.ImpulseCounterLogEntry.TABLE_NAME);

createElectricityMeterLogTable(db);
createImpulseCounterLogTable(db);


}

private void recreateViews(SQLiteDatabase db) {
execSQL(db, "DROP VIEW IF EXISTS "
+ SuplaContract.ChannelViewEntry.VIEW_NAME);
execSQL(db, "DROP VIEW IF EXISTS "
+ SuplaContract.ChannelGroupValueViewEntry.VIEW_NAME);
execSQL(db, "DROP VIEW IF EXISTS "
+ SuplaContract.ImpulseCounterLogViewEntry.VIEW_NAME);
execSQL(db, "DROP VIEW IF EXISTS "
+ SuplaContract.ElectricityMeterLogViewEntry.VIEW_NAME);

createChannelView(db);
createChannelGroupValueView(db);
createElectricityMeterLogView(db);
createImpulseCounterLogView(db);
}
Expand Down Expand Up @@ -740,6 +741,9 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
break;
}
}

// Recreate views on the end
recreateViews(db);
}

}
Expand Down

0 comments on commit ec83ba9

Please sign in to comment.