chore: remove stats table migration logic from ClickHouseSchemaInitializer
All checks were successful
CI / cleanup-branch (push) Has been skipped
CI / build (push) Successful in 1m48s
CI / docker (push) Successful in 1m9s
CI / deploy-feature (push) Has been skipped
CI / deploy (push) Successful in 1m44s

Not needed yet -- all deployments are under our control and can be
reset manually if the old schema is encountered.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-13 11:51:34 +02:00
parent 3f2392b8f7
commit 5edb833d21

View File

@@ -27,8 +27,6 @@ public class ClickHouseSchemaInitializer {
@EventListener(ApplicationReadyEvent.class)
public void initializeSchema() {
try {
migrateStatsTablesIfNeeded();
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource script = resolver.getResource("classpath:clickhouse/init.sql");
@@ -52,36 +50,4 @@ public class ClickHouseSchemaInitializer {
log.error("ClickHouse schema initialization failed — server will continue but ClickHouse features may not work", e);
}
}
/**
* One-time migration: stats tables originally used count()/countIf() which
* double-counted chunk retry duplicates. The new schema uses uniq()/uniqIf().
* Since AggregateFunction column types cannot be ALTERed, we must drop and
* let init.sql recreate them. MVs that depend on the tables are dropped first.
* Data rebuilds organically from new inserts via the materialized views.
*/
private void migrateStatsTablesIfNeeded() {
String[] statsTables = {
"stats_1m_all", "stats_1m_app", "stats_1m_route",
"stats_1m_processor", "stats_1m_processor_detail"
};
for (String table : statsTables) {
try {
Integer oldSchema = clickHouseJdbc.queryForObject(
"SELECT count() FROM system.columns " +
"WHERE database = currentDatabase() AND table = '" + table + "' " +
"AND name = 'total_count' AND type = 'AggregateFunction(count)'",
Integer.class);
if (oldSchema != null && oldSchema > 0) {
log.info("Migrating stats table '{}': dropping old count()-based schema", table);
clickHouseJdbc.execute("DROP VIEW IF EXISTS " + table + "_mv");
clickHouseJdbc.execute("DROP TABLE IF EXISTS " + table);
}
} catch (Exception e) {
log.warn("Could not check migration status for '{}': {}", table, e.getMessage());
}
}
}
}