diff options
author | desperateCoder <echotodevnull@gmail.com> | 2021-03-04 15:19:06 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2021-03-04 15:27:33 +0300 |
commit | 8532320302e465c2d0037c978bf2125d68e2cbb6 (patch) | |
tree | 4a9b9a25bd2fb2978550cb8e9365861deaef7964 /app/src/main/java/it | |
parent | ee175e5665679a165a9070a1686df1dd2b033ca1 (diff) |
#767 filter widget rewrite: migrate old StackWidgetModel to filter widget
Diffstat (limited to 'app/src/main/java/it')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java index 874568734..43870b57e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java @@ -1,8 +1,10 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db; +import android.content.ContentValues; import android.content.Context; import android.content.SharedPreferences; import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; import android.graphics.Color; import androidx.annotation.ColorInt; @@ -43,6 +45,7 @@ import it.niedermann.nextcloud.deck.model.ocs.projects.OcsProject; import it.niedermann.nextcloud.deck.model.ocs.projects.OcsProjectResource; import it.niedermann.nextcloud.deck.model.relations.UserInBoard; import it.niedermann.nextcloud.deck.model.relations.UserInGroup; +import it.niedermann.nextcloud.deck.model.widget.filter.EWidgetType; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidget; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetAccount; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetBoard; @@ -125,7 +128,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.fil FilterWidgetSort.class, }, exportSchema = false, - version = 26 + version = 27 ) @TypeConverters({DateTypeConverter.class, EnumConverter.class}) public abstract class DeckDatabase extends RoomDatabase { @@ -461,6 +464,49 @@ public abstract class DeckDatabase extends RoomDatabase { } }; + private static final Migration MIGRATION_26_27 = new Migration(26, 27) { + @Override + public void migrate(SupportSQLiteDatabase database) { + + Cursor cursor = database.query("select s.localId, s.boardId, s.accountId from `StackWidgetModel` w inner join `Stack` s on s.localId = w.stackId"); + while (cursor.moveToNext()) { + Long localStackId = cursor.getLong(0); + Long localBoardId = cursor.getLong(1); + Long accountId = cursor.getLong(2); + + // widget: + ContentValues values = new ContentValues(); + values.put("widgetType", EWidgetType.STACK_WIDGET.getId()); + long filterWidgetId = database.insert("FilterWidget", SQLiteDatabase.CONFLICT_NONE, values); + + // account + values = new ContentValues(); + values.put("filterWidgetId", filterWidgetId); + values.put("accountId", accountId); + values.put("includeNoUser", false); + values.put("includeNoProject", false); + long filterWidgetAccountId = database.insert("FilterWidgetAccount", SQLiteDatabase.CONFLICT_NONE, values); + + // board + values = new ContentValues(); + values.put("filterAccountId", filterWidgetAccountId); + values.put("boardId", localBoardId); + values.put("includeNoLabel", false); + long filterWidgetBoardId = database.insert("FilterWidgetBoard", SQLiteDatabase.CONFLICT_NONE, values); + + // stack + values = new ContentValues(); + values.put("filterBoardId", filterWidgetBoardId); + values.put("stackId", localStackId); + database.insert("FilterWidgetBoard", SQLiteDatabase.CONFLICT_NONE, values); + + + } + + // cleanup + database.execSQL("DROP TABLE `StackWidgetModel`"); + } + }; public static final RoomDatabase.Callback ON_CREATE_CALLBACK = new RoomDatabase.Callback() { @Override @@ -540,6 +586,7 @@ public abstract class DeckDatabase extends RoomDatabase { }) .addMigrations(MIGRATION_24_25) .addMigrations(MIGRATION_25_26) + .addMigrations(MIGRATION_26_27) .fallbackToDestructiveMigration() .addCallback(ON_CREATE_CALLBACK) .build(); |