-- Access log table: records every HTTP request that reaches the server
CREATE TABLE IF NOT EXISTS access_logs (
  id            BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  method        VARCHAR(10)     NOT NULL,
  path          TEXT            NOT NULL,
  ip_address    VARCHAR(45)     NOT NULL,
  user_agent    TEXT            DEFAULT NULL,
  status_code   SMALLINT UNSIGNED DEFAULT NULL,
  response_time_ms INT UNSIGNED DEFAULT NULL,
  user_id       VARCHAR(36)     DEFAULT NULL,
  tenant_id     VARCHAR(36)     DEFAULT NULL,
  sysadmin_id   VARCHAR(36)     DEFAULT NULL,
  created_at    DATETIME(3)     NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
  PRIMARY KEY (id),
  INDEX idx_access_logs_created_at (created_at),
  INDEX idx_access_logs_ip         (ip_address),
  INDEX idx_access_logs_user_id    (user_id),
  INDEX idx_access_logs_tenant_id  (tenant_id),
  INDEX idx_access_logs_sysadmin   (sysadmin_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
