Created
February 4, 2023 01:25
-
-
Save tateisu/2c80cdbb22b34b08ee1a9a0deab77cf8 to your computer and use it in GitHub Desktop.
Roomのスキーマ差異例外のダンプを比較するスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
fun splitTableInfo(src: String): List<String> { | |
val lines = ArrayList<String>() | |
val after = src.replace("""([\w_]+=Column\{[^}]+\}|Index\{[^}]+\}),? ?""".toRegex()) { | |
lines.add(it.groupValues[1]) | |
"" | |
} | |
lines.add(" :$after") | |
return lines.sorted() | |
} | |
fun String.fix() = | |
this.replace("""(type)=(\S+)""".toRegex()) { | |
"${it.groupValues[1]}=${it.groupValues[2].uppercase()}" | |
} | |
fun compareLines(lName: String, l: List<String>?, rName: String, r: List<String>?) { | |
println("${lName}.size=${l?.size}, ${rName}.size=${r?.size}") | |
var i = 0 | |
while (true) { | |
val lLine = l?.elementAtOrNull(i)?.fix() | |
val rLine = r?.elementAtOrNull(i)?.fix() | |
++i | |
if (lLine == null && rLine == null) break | |
if (lLine == rLine) { | |
if (lLine?.contains("TableInfo") == true) { | |
println("[$i] $lLine") | |
} | |
continue | |
} | |
if (lLine != null) println("[$i]${lName} $lLine") | |
if (rLine != null) println("[$i]${rName} $rLine") | |
if (lLine != null && rLine != null && lLine != rLine) { | |
println("line is not same") | |
} | |
} | |
} | |
fun main() { | |
var target = "" | |
val map = HashMap<String, List<String>>() | |
val lines = File("error.txt").readText() | |
.split("""[\x0d\x0a]+""".toRegex()) | |
.mapNotNull { | |
it.replace("""\A\s+""".toRegex(), "") | |
.replace("""\s+\z""".toRegex(), "") | |
.takeIf { l -> l.isNotBlank() } | |
} | |
for (line in lines) { | |
when (line) { | |
"Expected:" -> target = "e" | |
"Found:" -> target = "f" | |
else -> { | |
map[target] = splitTableInfo(line) | |
if (map.containsKey("e") && map.containsKey("f")) break | |
} | |
} | |
} | |
compareLines( | |
"Expect", map["e"], | |
"Actual", map["f"], | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
スキーマ差異例外でadb logに出る内容の例
こんなん人力で読んでたらハゲるわ