| 493 | } |
| 494 | |
| 495 | pub async fn get_latest_policy( |
| 496 | &self, |
| 497 | sandbox_id: &str, |
| 498 | ) -> PersistenceResult<Option<PolicyRecord>> { |
| 499 | let row = sqlx::query( |
| 500 | r#" |
| 501 | SELECT "id", "scope", "version", "status", "payload", "created_at_ms" |
| 502 | FROM "objects" |
| 503 | WHERE "object_type" = ?1 AND "scope" = ?2 |
| 504 | ORDER BY "version" DESC, "created_at_ms" DESC |
| 505 | LIMIT 1 |
| 506 | "#, |
| 507 | ) |
| 508 | .bind(POLICY_OBJECT_TYPE) |
| 509 | .bind(sandbox_id) |
| 510 | .fetch_optional(&self.pool) |
| 511 | .await |
| 512 | .map_err(|e| map_db_error(&e))?; |
| 513 | |
| 514 | row.map(row_to_policy_record).transpose() |
| 515 | } |
| 516 | |
| 517 | pub async fn get_latest_loaded_policy( |
| 518 | &self, |