feat(scripts): complete stack init + prod data import with date shift

Schema cleanup:
- Remove anubis_ua_rules table stub from 03_anubis_tables.sql
- Remove anubis_ua_rules from bot-detector deploy_schema.sql
- Remove UA seed step from clickhouse-init.sh (no more REGEXP_TREE dependency)
- Drop dict_anubis_ua, dict_anubis_country, anubis_ua_rules, anubis_country_rules

New scripts:
- scripts/init-stack.sh: comprehensive ClickHouse init (13 SQL files + migrations
  + validation + cleanup of obsolete tables). Supports --reset, --import-prod.
- scripts/import-prod-data.sh: imports pre-exported prod data (Native format)
  with dynamic date shift (max(time) → now). Supports --shift, --no-truncate.
- scripts/data/prod-export/: directory for cached Native format exports

Makefile targets: init-stack, import-prod-data, init-and-import

Tested: init-stack.sh passes all 13 SQL + 7 critical tables + 7 dicts
        import-prod-data.sh: 3M rows in ~37s with auto date shift
        Dashboard: 55 routes OK, bot-detector: 36/36 tests pass

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
toto
2026-04-09 21:40:05 +02:00
parent d8ca804a55
commit 9ea36ad22e
8 changed files with 437 additions and 54 deletions

View File

@ -34,16 +34,4 @@ for f in "$TMP_DIR"/*.sql; do
fi
done
# ---------------------------------------------------------------------------
# Seed data required for dictionaries to function
# REGEXP_TREE dictionaries require at least one rule; without it, any INSERT
# into http_logs_raw fails because the MV mv_http_logs calls dictGet() on
# the empty dict. Insert a catch-all "unknown" rule so the pipeline works.
# ---------------------------------------------------------------------------
echo "[init] Seeding anubis_ua_rules (REGEXP_TREE needs ≥1 rule)..."
clickhouse-client --multiquery <<'SEED'
INSERT INTO ja4_processing.anubis_ua_rules (id, parent_id, regexp, keys, values) VALUES
(1, 0, '.*', ['bot_name','action','has_ip','rule_id','category'], ['','','0','0','']);
SEED
echo "[init] All SQL files executed and seed data inserted"
echo "[init] All SQL files executed successfully"