fix(aria): convert all PostgreSQL named enum columns to VARCHAR
CD - Develop / build-and-deploy (push) Failing after 11m27s

All named enum types (threat_severity, attack_phase, event_type, ioc_type,
ioc_source, confidence_level, sequence_type, auto_response_action,
os_eol_status) have been converted to VARCHAR via V3 migration. Hibernate
@Enumerated(EnumType.STRING) binds values as character varying which
PostgreSQL rejects without explicit casts on both INSERT and SELECT.

Reverts the native @Query workarounds added in the previous two commits —
simple derived query methods now work correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 16:05:56 -04:00
parent 89a088c4b3
commit cf275d87d1
5 changed files with 39 additions and 14 deletions
@@ -52,7 +52,7 @@ public class DevicePostureController {
Pageable pageable = PageRequest.of(page, size);
if (osEolStatus != null) {
return postureRepository.findByOsEolStatusNativeOrderByPostureScoreAsc(osEolStatus.name(), pageable);
return postureRepository.findByOsEolStatusOrderByPostureScoreAsc(osEolStatus, pageable);
}
if ("low".equals(scoreFilter)) {
return postureRepository.findByPostureScoreLessThanOrderByPostureScoreAsc(50, pageable);
@@ -1,5 +1,6 @@
package com.hiveops.aria.controller;
import com.hiveops.aria.entity.DeviceSecurityPosture;
import com.hiveops.aria.entity.ThreatEvent;
import com.hiveops.aria.repository.DeviceSecurityPostureRepository;
import com.hiveops.aria.repository.PrecursorSequenceAlertRepository;
@@ -50,13 +51,13 @@ public class ThreatEventController {
@PreAuthorize("hasAnyRole('MSP_ADMIN','BCOS_ADMIN')")
public ResponseEntity<Map<String, Object>> getStats() {
long totalEvents = eventRepository.count();
long critical24h = eventRepository.countBySeverityNative("CRITICAL");
long high24h = eventRepository.countBySeverityNative("HIGH");
long critical24h = eventRepository.countBySeverity(ThreatEvent.ThreatSeverity.CRITICAL);
long high24h = eventRepository.countBySeverity(ThreatEvent.ThreatSeverity.HIGH);
long activeIocs = iocRepository.findByActiveTrue().size();
long activeSequences = sequenceAlertRepository.countByResolvedAtIsNull();
long lowPostureCount = postureRepository.countByPostureScoreLessThan(50);
long eolDeviceCount = postureRepository.countByOsEolStatusNative("EOL");
long eolDeviceCount = postureRepository.countByOsEolStatus(DeviceSecurityPosture.OsEolStatus.EOL);
return ResponseEntity.ok(Map.of(
"totalEvents", totalEvents,
@@ -4,8 +4,6 @@ import com.hiveops.aria.entity.DeviceSecurityPosture;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@@ -22,9 +20,8 @@ public interface DeviceSecurityPostureRepository extends JpaRepository<DeviceSec
long countByPostureScoreLessThan(int score);
@Query(value = "SELECT COUNT(*) FROM device_security_posture WHERE os_eol_status = CAST(:status AS os_eol_status)", nativeQuery = true)
long countByOsEolStatusNative(@Param("status") String status);
long countByOsEolStatus(DeviceSecurityPosture.OsEolStatus osEolStatus);
@Query(value = "SELECT * FROM device_security_posture WHERE os_eol_status = CAST(:status AS os_eol_status) ORDER BY posture_score ASC", nativeQuery = true, countQuery = "SELECT COUNT(*) FROM device_security_posture WHERE os_eol_status = CAST(:status AS os_eol_status)")
Page<DeviceSecurityPosture> findByOsEolStatusNativeOrderByPostureScoreAsc(@Param("status") String status, Pageable pageable);
Page<DeviceSecurityPosture> findByOsEolStatusOrderByPostureScoreAsc(
DeviceSecurityPosture.OsEolStatus osEolStatus, Pageable pageable);
}
@@ -4,8 +4,6 @@ import com.hiveops.aria.entity.ThreatEvent;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.time.Instant;
@@ -24,8 +22,7 @@ public interface ThreatEventRepository extends JpaRepository<ThreatEvent, Long>
Page<ThreatEvent> findBySeverityOrderByDetectedAtDesc(ThreatEvent.ThreatSeverity severity, Pageable pageable);
@Query(value = "SELECT COUNT(*) FROM threat_event WHERE severity = CAST(:severity AS threat_severity)", nativeQuery = true)
long countBySeverityNative(@Param("severity") String severity);
long countBySeverity(ThreatEvent.ThreatSeverity severity);
Page<ThreatEvent> findAllByOrderByDetectedAtDesc(Pageable pageable);
}
@@ -0,0 +1,30 @@
-- Convert all named PostgreSQL enum columns to VARCHAR.
-- Hibernate @Enumerated(EnumType.STRING) binds values as character varying;
-- named enum types reject implicit varchar casts on both INSERT and SELECT.
ALTER TABLE threat_event
ALTER COLUMN severity TYPE VARCHAR(20) USING severity::VARCHAR,
ALTER COLUMN event_type TYPE VARCHAR(30) USING event_type::VARCHAR,
ALTER COLUMN attack_phase TYPE VARCHAR(40) USING attack_phase::VARCHAR;
ALTER TABLE threat_ioc
ALTER COLUMN ioc_type TYPE VARCHAR(30) USING ioc_type::VARCHAR,
ALTER COLUMN ioc_source TYPE VARCHAR(20) USING ioc_source::VARCHAR,
ALTER COLUMN confidence_level TYPE VARCHAR(10) USING confidence_level::VARCHAR;
ALTER TABLE precursor_sequence_alert
ALTER COLUMN sequence_type TYPE VARCHAR(20) USING sequence_type::VARCHAR,
ALTER COLUMN auto_response_action TYPE VARCHAR(20) USING auto_response_action::VARCHAR;
ALTER TABLE device_security_posture
ALTER COLUMN os_eol_status TYPE VARCHAR(20) USING os_eol_status::VARCHAR;
DROP TYPE IF EXISTS threat_severity CASCADE;
DROP TYPE IF EXISTS threat_event_type CASCADE;
DROP TYPE IF EXISTS attack_phase CASCADE;
DROP TYPE IF EXISTS ioc_type CASCADE;
DROP TYPE IF EXISTS ioc_source CASCADE;
DROP TYPE IF EXISTS confidence_level CASCADE;
DROP TYPE IF EXISTS sequence_type CASCADE;
DROP TYPE IF EXISTS auto_response_action CASCADE;
DROP TYPE IF EXISTS os_eol_status CASCADE;