|
|
@@ -0,0 +1,37 @@
|
|
|
+package com.etotem.cfc.config;
|
|
|
+
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
+import org.mockito.ArgumentCaptor;
|
|
|
+import org.mockito.InjectMocks;
|
|
|
+import org.mockito.Mock;
|
|
|
+import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
+
|
|
|
+/**
|
|
|
+ * FamilyWorkbench 2026-11-13:tasks 必须有 (family_id, created_at) 复合索引,
|
|
|
+ * 支撑「单家庭工作台」按家庭聚合计数与近 30 天逐日趋势(GROUP BY DATE(created_at))。
|
|
|
+ * 无此索引时该分桶在 tasks 大表上为全表扫描。
|
|
|
+ */
|
|
|
+@ExtendWith(MockitoExtension.class)
|
|
|
+class TasksFamilyCreatedIndexMigrationTest {
|
|
|
+
|
|
|
+ @Mock
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ @InjectMocks
|
|
|
+ private DatabaseInitializer initializer;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void 迁移为tasks添加家庭维度趋势索引() {
|
|
|
+ initializer.addTasksFamilyCreatedIndex();
|
|
|
+
|
|
|
+ ArgumentCaptor<String> sql = ArgumentCaptor.forClass(String.class);
|
|
|
+ verify(jdbcTemplate).execute(sql.capture());
|
|
|
+ assertTrue(sql.getValue().contains("ADD INDEX idx_family_created (family_id, created_at)"),
|
|
|
+ "tasks 表必须有 (family_id, created_at) 索引以支撑工作台趋势/计数分桶");
|
|
|
+ }
|
|
|
+}
|