fix: sort ClickHouse migration scripts by numeric version prefix
Alphabetical sort put V10/V11 before V2-V9 ("V11" < "V1_" in ASCII),
causing the route_diagrams projection to run before the table existed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -35,7 +35,17 @@ public class ClickHouseSchemaInitializer {
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
Resource[] scripts = resolver.getResources("classpath:clickhouse/*.sql");
|
||||
|
||||
Arrays.sort(scripts, Comparator.comparing(Resource::getFilename));
|
||||
// Sort by numeric version prefix (V1, V2, ..., V10, V11) — not alphabetically
|
||||
Arrays.sort(scripts, Comparator.comparingInt(r -> {
|
||||
String name = r.getFilename();
|
||||
if (name != null && name.startsWith("V")) {
|
||||
int end = name.indexOf('_');
|
||||
if (end > 1) {
|
||||
try { return Integer.parseInt(name.substring(1, end)); } catch (NumberFormatException ignored) {}
|
||||
}
|
||||
}
|
||||
return Integer.MAX_VALUE;
|
||||
}));
|
||||
|
||||
for (Resource script : scripts) {
|
||||
String sql = script.getContentAsString(StandardCharsets.UTF_8);
|
||||
|
||||
Reference in New Issue
Block a user