e1c97038d4
SQLite was too slow for analytical aggregations on traffic_events and waf_events (millions of rows, GROUP BY, COUNT DISTINCT). ClickHouse is a columnar OLAP database purpose-built for this workload. - Add ClickHouse container to Docker Compose with health check - Create src/lib/clickhouse/client.ts with singleton client, table DDL, insert helpers, and all analytics query functions - Update log-parser.ts and waf-log-parser.ts to write to ClickHouse - Remove purgeOldEntries — ClickHouse TTL handles 90-day retention - Rewrite analytics-db.ts and waf-events.ts to query ClickHouse - Remove trafficEvents/wafEvents from SQLite schema, add migration - CLICKHOUSE_PASSWORD is required (no hardcoded default) - Update .env.example, README, and test infrastructure API response shapes are unchanged — no frontend modifications needed. Parse state (file offsets) remains in SQLite. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
31 lines
932 B
TypeScript
31 lines
932 B
TypeScript
import { execFileSync } from 'node:child_process';
|
|
import { rmSync, existsSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
|
|
const COMPOSE_ARGS = [
|
|
'compose',
|
|
'-f', 'docker-compose.yml',
|
|
'-f', 'tests/docker-compose.test.yml',
|
|
];
|
|
|
|
export default async function globalTeardown() {
|
|
console.log('[global-teardown] Stopping Docker Compose test stack...');
|
|
try {
|
|
execFileSync('docker', [...COMPOSE_ARGS, 'down', '-v', '--remove-orphans'], {
|
|
stdio: 'inherit',
|
|
cwd: process.cwd(),
|
|
env: { ...process.env, CLICKHOUSE_PASSWORD: 'test-clickhouse-password-2026' },
|
|
});
|
|
} catch (err) {
|
|
console.warn('[global-teardown] docker compose down failed:', err);
|
|
}
|
|
|
|
const authDir = resolve(__dirname, '.auth');
|
|
if (existsSync(authDir)) {
|
|
rmSync(authDir, { recursive: true, force: true });
|
|
console.log('[global-teardown] Removed', authDir);
|
|
}
|
|
|
|
console.log('[global-teardown] Done.');
|
|
}
|