recent-errors built its result by ranking ALL occurrences of every matching incident with ROW_NUMBER() before applying LIMIT, so status=resolved (the majority, longest-lived incident state) forced a scan of the full historical occurrence log just to return one page. admin/incidents.ts already filters/orders er_incidents directly for this reason; apply the same pattern here: page through er_incidents first (small, indexed by current_state), then rank occurrences only for that page. The q= search path is kept on the old occurrence-first query since it needs to match occurrence content across an incident's full history. Adds er_incidents_state_seen_idx (current_state, last_seen_at) so the new incident-first path stays indexed even without a project_slug filter, and backfills the docker/local migration runners that had drifted behind deploy/lxc/run-migrate.sh (missing three prior migrations), since the new migration needs to run through them too. Verified locally against MariaDB (docker compose) with 3k resolved / 20 open incidents and ~90k synthetic occurrences: the reported repro curls now return HTTP 200 in <100ms (previously reproduced as a hang via manual EXPLAIN/timing of the old query, ~2s at this seed size and scaling with total occurrence history).
37 lines
1.8 KiB
Bash
Executable File
37 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Apply error_reporting + admin SQL migrations and error_reporting seeds (Compose one-shot).
|
|
set -euo pipefail
|
|
|
|
: "${MARIADB_HOST:=mariadb}"
|
|
: "${MARIADB_USER:?MARIADB_USER required}"
|
|
: "${MARIADB_PASSWORD:?MARIADB_PASSWORD required}"
|
|
: "${MARIADB_DATABASE:?MARIADB_DATABASE required}"
|
|
|
|
echo "docker-migrate: waiting for ${MARIADB_HOST}..."
|
|
until mariadb-admin ping -h "${MARIADB_HOST}" -u "${MARIADB_USER}" -p"${MARIADB_PASSWORD}" --silent; do
|
|
sleep 1
|
|
done
|
|
|
|
_run_sql_file() {
|
|
_path="$1"
|
|
echo "docker-migrate: applying ${_path}"
|
|
mariadb -h "${MARIADB_HOST}" -u "${MARIADB_USER}" -p"${MARIADB_PASSWORD}" "${MARIADB_DATABASE}" < "${_path}"
|
|
}
|
|
|
|
_run_sql_file "/migrations/error_reporting/20260322043000_create_error_reporting_core.up.sql"
|
|
_run_sql_file "/migrations/error_reporting/20260322044000_create_error_occurrences_and_states.up.sql"
|
|
_run_sql_file "/migrations/error_reporting/20260322044500_add_ingest_idempotency.up.sql"
|
|
_run_sql_file "/migrations/error_reporting/20260322045000_create_collectors_retention_and_audit.up.sql"
|
|
_run_sql_file "/migrations/error_reporting/20260402103000_add_occurred_at_for_stats.up.sql"
|
|
_run_sql_file "/migrations/error_reporting/20260402140000_ingest_key_rate_limits.up.sql"
|
|
_run_sql_file "/migrations/error_reporting/20260608150000_retire_wdmi_projects.up.sql"
|
|
_run_sql_file "/migrations/error_reporting/20260824120000_add_incidents_state_seen_idx.up.sql"
|
|
_run_sql_file "/migrations/admin/001_admin_users.sql"
|
|
_run_sql_file "/migrations/admin/002_admin_refresh_tokens.sql"
|
|
_run_sql_file "/migrations/admin/003_audit_logs.sql"
|
|
_run_sql_file "/migrations/admin/004_seed_superadmin.sql"
|
|
_run_sql_file "/seed/error_reporting/dev_two_projects.sql"
|
|
_run_sql_file "/seed/error_reporting/dev_collector_http_fixture.sql"
|
|
|
|
echo "docker-migrate: complete"
|