Files
HealthLog/prisma/migrations/0061_audit_log_carrier/migration.sql
T
Marc-André Bombeck 1d8b80698e feat(audit): wire ASN+carrier into the audit-log create/update path
Completes the v1.4.27 B3 audit-log work that landed in e8fb0a75. The
prior commit shipped the backfill helper but the schema + migration
+ audit.ts write-path were dropped during a concurrent staging
window. This commit puts them back.

`prisma/schema.prisma` grows two nullable columns on AuditLog (`asn`
+ `carrier`), the matching idempotent `IF NOT EXISTS`-guarded
migration lands at `0061_audit_log_carrier`, and the auditLog helper
resolves location + ASN row in parallel (single 3 s race, single
`prisma.auditLog.update` carries whichever fields the resolvers
filled).

Test coverage: five new cases on audit.test.ts cover all four
combinations of location/ASN hit-or-miss plus a row with no
carrier organisation.
2026-05-15 16:43:48 +02:00

21 lines
934 B
SQL

-- v1.4.27 B3 — Persist the ASN + carrier on login audit rows.
--
-- The bundled MaxMind GeoLite2-ASN MMDB resolves an autonomous-system
-- number and the organisation string ("Deutsche Telekom AG") at
-- audit-creation time. Both columns are nullable so the schema stays
-- valid for older rows, for private/loopback IPs that skip the
-- lookup entirely, and for offline-miss rows that the resolver could
-- not match.
--
-- asn — INTEGER, the autonomous-system number from the MMDB.
-- carrier — TEXT, the autonomous-system organisation string.
--
-- The `IF NOT EXISTS` guards make the migration idempotent — the
-- demo server may already carry hand-edited columns from a prior
-- partial run, and the same migration must apply cleanly to a fresh
-- database. Same posture as 0058_user_research_mode.
ALTER TABLE "audit_logs"
ADD COLUMN IF NOT EXISTS "asn" INTEGER,
ADD COLUMN IF NOT EXISTS "carrier" TEXT;