Сервер: исправить автоинициализацию PostgreSQL schema v1

This commit is contained in:
AidarKC
2026-07-24 21:24:06 +04:00
parent 5326ad85d8
commit bfdada6792
2 changed files with 78 additions and 20 deletions
@@ -787,33 +787,88 @@ public final class DatabaseInitializer {
List<String> statements = new ArrayList<>();
StringBuilder current = new StringBuilder();
boolean inSingleQuote = false;
boolean inLineComment = false;
boolean inBlockComment = false;
String dollarQuoteTag = null;
for (int i = 0; i < sqlScript.length(); i++) {
char ch = sqlScript.charAt(i);
if (dollarQuoteTag == null && ch == '\'' && !isEscapedSingleQuote(sqlScript, i)) {
inSingleQuote = !inSingleQuote;
if (inLineComment) {
current.append(ch);
if (ch == '\n') {
inLineComment = false;
}
continue;
}
if (inBlockComment) {
current.append(ch);
if (ch == '*' && i + 1 < sqlScript.length() && sqlScript.charAt(i + 1) == '/') {
current.append('/');
i += 1;
inBlockComment = false;
}
continue;
}
if (dollarQuoteTag != null) {
if (startsWithAt(sqlScript, i, dollarQuoteTag)) {
current.append(dollarQuoteTag);
i += dollarQuoteTag.length() - 1;
dollarQuoteTag = null;
} else {
current.append(ch);
}
continue;
}
if (inSingleQuote) {
current.append(ch);
if (ch == '\'') {
if (i + 1 < sqlScript.length() && sqlScript.charAt(i + 1) == '\'') {
current.append('\'');
i += 1;
} else {
inSingleQuote = false;
}
}
continue;
}
if (ch == '-' && i + 1 < sqlScript.length() && sqlScript.charAt(i + 1) == '-') {
current.append("--");
i += 1;
inLineComment = true;
continue;
}
if (ch == '/' && i + 1 < sqlScript.length() && sqlScript.charAt(i + 1) == '*') {
current.append("/*");
i += 1;
inBlockComment = true;
continue;
}
if (ch == '\'') {
inSingleQuote = true;
current.append(ch);
continue;
}
if (!inSingleQuote) {
String tag = readDollarQuoteTag(sqlScript, i);
if (tag != null) {
current.append(tag);
i += tag.length() - 1;
if (dollarQuoteTag == null) {
dollarQuoteTag = tag;
} else if (dollarQuoteTag.equals(tag)) {
dollarQuoteTag = null;
}
continue;
}
}
if (ch == ';' && !inSingleQuote && dollarQuoteTag == null) {
if (ch == ';') {
String statement = current.toString().trim();
if (!statement.isEmpty()) {
statements.add(current.toString());
}
current.setLength(0);
continue;
}
@@ -822,13 +877,16 @@ public final class DatabaseInitializer {
}
if (!current.isEmpty()) {
String statement = current.toString().trim();
if (!statement.isEmpty()) {
statements.add(current.toString());
}
}
return statements;
}
private static boolean isEscapedSingleQuote(String sqlScript, int index) {
return index + 1 < sqlScript.length() && sqlScript.charAt(index + 1) == '\'';
private static boolean startsWithAt(String sqlScript, int index, String token) {
return sqlScript.regionMatches(index, token, 0, token.length());
}
private static String readDollarQuoteTag(String sqlScript, int index) {
+1 -1
View File
@@ -1,2 +1,2 @@
client.version=1.2.354
server.version=1.2.320
server.version=1.2.321