chore: remove stats table migration logic from ClickHouseSchemaInitializer
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:
@@ -27,8 +27,6 @@ public class ClickHouseSchemaInitializer {
|
|||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
public void initializeSchema() {
|
public void initializeSchema() {
|
||||||
try {
|
try {
|
||||||
migrateStatsTablesIfNeeded();
|
|
||||||
|
|
||||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||||
Resource script = resolver.getResource("classpath:clickhouse/init.sql");
|
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);
|
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user