Skip to content

Commit

Permalink
fix h2 converter v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
vdiskg committed Feb 2, 2024
1 parent 06afabb commit d68ed97
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ private static String convertTableConfig(String convertedText, SqlStatement sqlS
}

private static final Pattern INDEX_NAME_PATTERN = Pattern.compile(
"(KEY\\s*`|KEY\\s+)(?<indexName>[a-zA-Z0-9\\-_]+)(`)?", Pattern.CASE_INSENSITIVE);
// KEY `AppId_ClusterName_GroupName`
"(KEY\\s*`|KEY\\s+)(?<indexName>[a-zA-Z0-9\\-_]+)(`)?\\s*"
// (`AppId`,`ClusterName`(191),`NamespaceName`(191))
+ "\\((?<indexColumns>"
+ "(`)?[a-zA-Z0-9\\-_]+(`)?\\s*(\\([0-9]+\\))?"
+ "(,"
+ "(`)?[a-zA-Z0-9\\-_]+(`)?\\s*(\\([0-9]+\\))?"
+ ")*"
+ ")\\)",
Pattern.CASE_INSENSITIVE);

private static String convertIndexWithTable(String convertedText, String tableName,
SqlStatement sqlStatement) {
Expand All @@ -147,7 +156,8 @@ private static String convertIndexWithTable(String convertedText, String tableNa
// KEY `tableName_AppId_ClusterName_GroupName` (`AppId`,`ClusterName`(191),`NamespaceName`(191))
Matcher indexNameMatcher = INDEX_NAME_PATTERN.matcher(convertedLine);
if (indexNameMatcher.find()) {
convertedLine = indexNameMatcher.replaceAll("KEY `" + tableName + "_${indexName}`");
convertedLine = indexNameMatcher.replaceAll(
"KEY `" + tableName + "_${indexName}` (${indexColumns})");
}
convertedLine = removePrefixIndex(convertedLine);
}
Expand Down Expand Up @@ -203,7 +213,8 @@ private static String convertAlterTable(String convertedText, SqlStatement sqlSt
"\\s*ADD\\s+(?<indexType>(UNIQUE\\s+)?INDEX)\\s+(`)?(?<indexName>[a-zA-Z0-9\\-_]+)(`)?(?<subStatement>.*)[,;]",
Pattern.CASE_INSENSITIVE);
private static final Pattern DROP_INDEX_PATTERN = Pattern.compile(
"\\s*DROP\\s+INDEX\\s+(`)?(?<indexName>[a-zA-Z0-9\\-_]+)(`)?\\s*[,;]", Pattern.CASE_INSENSITIVE);
"\\s*DROP\\s+INDEX\\s+(`)?(?<indexName>[a-zA-Z0-9\\-_]+)(`)?\\s*[,;]",
Pattern.CASE_INSENSITIVE);

private static String convertAlterTableMulti(String convertedText, SqlStatement sqlStatement,
String tableName) {
Expand Down

0 comments on commit d68ed97

Please sign in to comment.