From 579a761f923fd008d844353779be7785ac428313 Mon Sep 17 00:00:00 2001 From: Rick Busarow Date: Wed, 5 Aug 2020 23:26:12 -0500 Subject: [PATCH] preserve indices when recreating a table --- .../matrix/roomigrant/compiler/Migration.kt | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/RoomigrantCompiler/src/main/java/dev/matrix/roomigrant/compiler/Migration.kt b/RoomigrantCompiler/src/main/java/dev/matrix/roomigrant/compiler/Migration.kt index daf57b0..cdb6d4f 100644 --- a/RoomigrantCompiler/src/main/java/dev/matrix/roomigrant/compiler/Migration.kt +++ b/RoomigrantCompiler/src/main/java/dev/matrix/roomigrant/compiler/Migration.kt @@ -124,15 +124,22 @@ class Migration( sb.append(" FROM `").append(table1!!.name).append("`") execSql(sb.toString()) + tableDiff.indicesDiff.same.forEach { + createTableIndex(table2, it) + } + tableDiff.indicesDiff.added.forEach { + createTableIndex(table2, it) + } dropTable(table1.name) renameTable(tableMerge.name, table2.name) - } + } else { - tableDiff.indicesDiff.removed.forEach { - dropTableIndex(it) - } - tableDiff.indicesDiff.added.forEach { - createTableIndex(table2, it) + tableDiff.indicesDiff.removed.forEach { + dropTableIndex(it) + } + tableDiff.indicesDiff.added.forEach { + createTableIndex(table2, it) + } } } @@ -148,7 +155,7 @@ class Migration( val old = viewDiff.old val new = viewDiff.new - old?.name?.let { dropView(it)} + old?.name?.let { dropView(it) } createView(new) }