Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2f6a2e7c authored by Philip Whitehouse's avatar Philip Whitehouse
Browse files

Fix multi-run upgrade bug in Migration

parent 902506b2
Loading
Loading
Loading
Loading
+31 −13
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ public class MigrationTo56 {

    public static void migratePendingCommands(SQLiteDatabase db) {
        List<PendingCommand> pendingCommmands = new ArrayList<>();

        if (columnExists(db, "pending_commands", "arguments")) {
            for (OldPendingCommand oldPendingCommand : getPendingCommands(db)) {
                PendingCommand newPendingCommand = migratePendingCommand(oldPendingCommand);
                pendingCommmands.add(newPendingCommand);
@@ -52,6 +54,22 @@ public class MigrationTo56 {
                db.insert("pending_commands", "command", cv);
            }
        }
    }

    private static boolean columnExists(SQLiteDatabase db, String table, String columnName) {
        Cursor columnCursor  = db.rawQuery("PRAGMA table_info("+table+")", null);
        columnCursor.moveToFirst();
        boolean foundColumn = false;
        while (!columnCursor.isAfterLast()) {
            if(columnCursor.getString(1).equals(columnName)) {
                foundColumn = true;
                break;
            }
            columnCursor.moveToNext();
        }
        columnCursor.close();
        return foundColumn;
    }

    @VisibleForTesting
    static PendingCommand migratePendingCommand(OldPendingCommand oldPendingCommand) {