diff --git a/cameleer3-server-app/src/main/java/com/cameleer3/server/app/config/ClickHouseSchemaInitializer.java b/cameleer3-server-app/src/main/java/com/cameleer3/server/app/config/ClickHouseSchemaInitializer.java index f666de39..85171872 100644 --- a/cameleer3-server-app/src/main/java/com/cameleer3/server/app/config/ClickHouseSchemaInitializer.java +++ b/cameleer3-server-app/src/main/java/com/cameleer3/server/app/config/ClickHouseSchemaInitializer.java @@ -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()); - } - } - } }