feat: version-specific pg_restore failure reasons, keep pg_stat_statements, explain reconcile conflicts

- pg_restore's stderr is kept; the archive header names the pg_dump that wrote it, and a newer one than
  the local client gives 'install a PostgreSQL client >= N' before any safety backup is taken
- omit_pg_stat_statements recreates the extension the target had, where it lived
- reconcile on a job that needs no recovery answers 409 with a reason
- proven against a real PostgreSQL server (real archive header, extension kept, mutation caught)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 14:46:37 +07:00
parent b104aa8053
commit 76999f06b8
4 changed files with 440 additions and 12 deletions

View File

@@ -1702,3 +1702,40 @@ async fn a_restore_safety_copy_never_pushes_a_production_capture_out_of_retentio
assert!(vault.get_snapshot(capture).unwrap().is_some());
assert!(vault.get_snapshot(safety[0]).unwrap().is_some());
}
#[tokio::test]
async fn reconciling_a_job_that_needs_no_recovery_says_so() {
let lab = fresh().await;
lab.start(&lab.admin(), "reconcile").await;
lab.capture(&Lab::production_identity(), false)
.await
.unwrap();
lab.tick().await;
let (job, _token) = lab.restore_until_ready().await.unwrap();
let uri = format!("/api/v1/restore-jobs/{job}/reconcile");
let (status, body) = lab
.send(
&lab.admin(),
"POST",
&uri,
Some(json!({"confirmation": format!("RECONCILE {job}")})),
)
.await;
assert_eq!(status, StatusCode::CONFLICT);
assert!(
body["error"]
.as_str()
.is_some_and(|text| text.contains("recovery_required")),
"{body}"
);
// the wrong confirmation is still a plain 400
let (status, _) = lab
.send(
&lab.admin(),
"POST",
&uri,
Some(json!({"confirmation": "no"})),
)
.await;
assert_eq!(status, StatusCode::BAD_REQUEST);
}

View File

@@ -277,17 +277,23 @@ async fn reconcile(
headers: HeaderMap,
Path(id): Path<Uuid>,
Json(body): Json<Reconcile>,
) -> Result<StatusCode, StatusCode> {
let actor = admin_write(&state, peer, &headers)?;
) -> Result<StatusCode, (StatusCode, Json<serde_json::Value>)> {
let plain = |status: StatusCode| (status, Json(serde_json::Value::Null));
let actor = admin_write(&state, peer, &headers).map_err(plain)?;
if body.confirmation != format!("RECONCILE {id}") {
return Err(StatusCode::BAD_REQUEST);
return Err(plain(StatusCode::BAD_REQUEST));
}
if !state
.db
.reconcile_restore(id, &actor.id(), now())
.map_err(internal)?
.map_err(|error| plain(internal(error)))?
{
return Err(StatusCode::CONFLICT);
return Err((
StatusCode::CONFLICT,
Json(serde_json::json!({
"error": "only a restore job in recovery_required can be reconciled"
})),
));
}
Ok(StatusCode::NO_CONTENT)
}