fix(aria): add BIGSERIAL PK to device_security_posture, fix JPA persist error
CD - Develop / build-and-deploy (push) Failing after 15m8s
CD - Develop / build-and-deploy (push) Failing after 15m8s
V4 migration drops the device_id primary key and adds an auto-generated
id BIGSERIAL as the PK. device_id becomes a unique nullable column.
Agents that don't send a numeric deviceId can now save posture reports.
Controller GET /{deviceId} now uses findByDeviceId instead of findById.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -66,7 +66,7 @@ public class DevicePostureController {
|
|||||||
@GetMapping("/{deviceId}")
|
@GetMapping("/{deviceId}")
|
||||||
@PreAuthorize("hasAnyRole('MSP_ADMIN','BCOS_ADMIN')")
|
@PreAuthorize("hasAnyRole('MSP_ADMIN','BCOS_ADMIN')")
|
||||||
public ResponseEntity<DeviceSecurityPosture> getPosture(@PathVariable Long deviceId) {
|
public ResponseEntity<DeviceSecurityPosture> getPosture(@PathVariable Long deviceId) {
|
||||||
return postureRepository.findById(deviceId)
|
return postureRepository.findByDeviceId(deviceId)
|
||||||
.map(ResponseEntity::ok)
|
.map(ResponseEntity::ok)
|
||||||
.orElse(ResponseEntity.notFound().build());
|
.orElse(ResponseEntity.notFound().build());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ import java.time.Instant;
|
|||||||
public class DeviceSecurityPosture {
|
public class DeviceSecurityPosture {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
@Column(name = "device_id")
|
@Column(name = "device_id")
|
||||||
private Long deviceId;
|
private Long deviceId;
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public interface DeviceSecurityPostureRepository extends JpaRepository<DeviceSec
|
|||||||
|
|
||||||
Optional<DeviceSecurityPosture> findByDeviceAgentId(String deviceAgentId);
|
Optional<DeviceSecurityPosture> findByDeviceAgentId(String deviceAgentId);
|
||||||
|
|
||||||
|
Optional<DeviceSecurityPosture> findByDeviceId(Long deviceId);
|
||||||
|
|
||||||
Page<DeviceSecurityPosture> findAllByOrderByPostureScoreAsc(Pageable pageable);
|
Page<DeviceSecurityPosture> findAllByOrderByPostureScoreAsc(Pageable pageable);
|
||||||
|
|
||||||
Page<DeviceSecurityPosture> findByPostureScoreLessThanOrderByPostureScoreAsc(
|
Page<DeviceSecurityPosture> findByPostureScoreLessThanOrderByPostureScoreAsc(
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
-- device_security_posture used device_id BIGINT as its primary key,
|
||||||
|
-- requiring callers to supply the numeric device ID. Agents only know
|
||||||
|
-- their string deviceAgentId, so inserts without a deviceId failed.
|
||||||
|
-- Add a proper auto-generated id column as the PK; make device_id a
|
||||||
|
-- nullable unique column (FK concept, populated when known).
|
||||||
|
|
||||||
|
ALTER TABLE device_security_posture DROP CONSTRAINT device_security_posture_pkey;
|
||||||
|
|
||||||
|
ALTER TABLE device_security_posture
|
||||||
|
ADD COLUMN id BIGSERIAL PRIMARY KEY;
|
||||||
|
|
||||||
|
ALTER TABLE device_security_posture
|
||||||
|
ADD CONSTRAINT uq_posture_device_id UNIQUE (device_id);
|
||||||
Reference in New Issue
Block a user