Skip to content

feat(postgres): set and show the point-in-time recovery window - #858

Merged
frodesundby merged 2 commits into
mainfrom
feat/postgres-recovery-window
Nov 23, 2026
Merged

frodesundby merged 2 commits into
mainfrom
feat/postgres-recovery-window

Conversation

@frodesundby

Copy link
Copy Markdown
Contributor

Hvorfor

Nais API (nais/api#639) og Console (nais/console-frontend#778) lar brukere lese og sette PITR-vinduet (backupRetentionDays). Dette er CLI-delen.

Hva

  • nais postgres create og nais postgres update får --recovery-window-days (2–30). Ugyldige verdier avvises før API-kall.
  • update viser gammel og ny verdi i sammenligningstabellen og advarer når vinduet forkortes, siden eldre backup da fjernes permanent.
  • nais postgres get viser vinduet og tidligste gjenopprettingspunkt (lokal tid). JSON har recoveryWindow.days og recoveryWindow.earliestRestorePoint (UTC).
  • Tester for utvidelse, forkorting, kombinasjon med andre endringer, ugyldige verdier og get i tekst og JSON.
  • Flagget er ikke lagt på clone; en klon får plattformens standard (2 dager).

Merk

  • schema.graphql er hentet fra live API og diffen er stor (277 linjer) siden prod har andre endringer siden sist. Branch-typene er borte (refactor(postgres): remove branches api#636), så de tre branch-oppføringene i TestPostgresActivityEntriesCanBeListed er fjernet.
  • --recovery-window-days 0 tolkes som ikke satt, som de andre tallflaggene.

Ikke verifisert

Ikke kjørt mot ekte API, bare mot testserver.

Add --recovery-window-days (2-30) to postgres create and update, and show the
window and earliest restore point in postgres get. Shortening the window warns
that older backups are removed. Schema updated from the live API, which no
longer has Postgres branch activity entries.
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

📝 Changelog preview

Below is a preview of the Changelog that will be added to the next release. Only commit messages that follow the Conventional Commits specification will be included in the Changelog.

v8.7.0 - 2026-11-23

Full Changelog: v8.6.0...v8.7.0

🚀 Features

  • (postgres) Set and show the point-in-time recovery window (be51b92)

🐛 Bug Fixes

  • (postgres) Validate recovery window before any API call (611f242)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Recovery-window range validation occurs after an API call, allowing authentication or discovery errors to mask invalid input rather than rejecting it before any API requests.

1 open issue
What changed in this PR

Adds Postgres point-in-time recovery window controls to the Nais CLI, complementing the API and Console support.

Changes:

  • Adds --recovery-window-days to create and update, with range validation, comparison output, and warnings when shortening retention.
  • Shows the recovery window and earliest restore point in text and JSON output; clone behavior remains unchanged.
  • Adds validation and output tests, refreshes the API schema and generated client, and removes obsolete branch activity fixtures.
File Description
schema.graphql Adds retention fields and incorporates live API schema changes.
internal/​postgres/​instance.go Preserves omission semantics for retention mutation inputs.
internal/​postgres/​get.go Queries retention days and earliest restore time.
internal/​postgres/​command/​recovery_window_test.go Tests range validation and zero-as-unset behavior.
internal/​postgres/​command/​instance.go Wires retention into create/update and adds shortening warnings.
internal/​postgres/​command/​instance_update_test.go Tests retention changes, warnings, and invalid values.
internal/​postgres/​command/​get.go Displays recovery details in local time and UTC JSON.
internal/​postgres/​command/​get_test.go Checks recovery-window text and JSON output.
internal/​postgres/​command/​flag/​flag.go Declares recovery-window flags and help text.
internal/​naisapi/​gql/​generated.go Regenerates client types and queries for the refreshed schema.
internal/​activity/​activity_test.go Removes fixtures for retired branch activity types.

Review effort: Balanced

Comment thread internal/postgres/command/instance.go Resolved
@frodesundby
frodesundby merged commit a5d82b4 into main Nov 23, 2026
22 checks passed
@frodesundby
frodesundby deleted the feat/postgres-recovery-window branch November 23, 2026 13:49
frodesundby added a commit to nais/doc that referenced this pull request Nov 23, 2026
Dokumenterer PITR-vinduet (`backupRetentionDays`) som nå kan settes i
manifest, CLI og Console (nais/pgrator#225, #230, nais/api#639,
nais/console-frontend#778, nais/cli#858).

- Ny referanseside `reference/recovery-window.md`: område (2–30 dager),
standard (2), hva som beholdes og slettes, hvor vinduet vises, og
hvordan kostnadsestimatet i Console beregnes.
- `how-to/create.md` og `how-to/manage.md`: nytt valg i manifest
(`spec.backup.retentionDays`), CLI (`--recovery-window-days`) og
Console, med advarsel om at forkorting sletter eldre backup permanent.
- `README.md` og `reference/cloning.md`: lenker, og at en klon ikke
arver kildens vindu.

`reference/spec.md` er generert fra pgrator og allerede oppdatert.

Bør ikke merges før CLI- og Console-PR-ene er ute i prod.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants