Skip to content

OBJ-80 — Restore API (creates a new version) - #26

Merged
objectgyan merged 2 commits into
mainfrom
objectgyan/obj-80-m45-restore-api-creates-a-new-version
May 17, 2026
Merged

objectgyan merged 2 commits into
mainfrom
objectgyan/obj-80-m45-restore-api-creates-a-new-version

Conversation

@objectgyan

Copy link
Copy Markdown
Owner

Summary

  • Adds POST /api/documents/{id}/restore?version=N endpoint that creates a new document_versions row by copying the body of version N, setting version_number = MAX+1 and restored_from = N.
  • Version N is never mutated — restore is non-destructive.
  • Returns 404 when the document or version N does not exist (tenant-scoped via EF Core query filter).
  • No new migration required: restored_from (nullable int) column was already present from the OBJ-76 AddDocumentVersions migration.

Changes

Layer Change
IDocumentService New RestoreVersionAsync(documentId, fromVersionNumber) method
DocumentService Implementation with row-level FOR UPDATE lock for monotonic version numbering
Program.cs POST /api/documents/{id:guid}/restore minimal API endpoint
RestoreApiTests.cs 4 integration tests covering happy path, 404 on missing version, 404 on missing document, 400 on missing param
validate-obj-80.ps1 Full validation script: build → unit tests → Postgres → migrations → integration tests → live API → DB assertion

Test plan

  • Build: 0 warnings, 0 errors
  • 190/190 tests passing (127 unit + 63 integration)
  • scripts/validate-obj-80.ps1 exits 0
  • DB query confirms version_number=4, restored_from=1 after restoring v1 of 3-version doc
  • Full JSON body equality: v4.body == v1.body
  • 404 on non-existent version; DB COUNT confirms no spurious row inserted
  • 404 on non-existent document

POST /api/documents/{id}/restore?version=N creates a new document_versions
row whose body is copied from version N, with version_number = MAX+1 and
restored_from = N. Version N is never mutated. Returns 404 when the document
or the requested version does not exist.

The restored_from column was already present from the AddDocumentVersions
migration (OBJ-76), so no new migration is required.
@linear-code

linear-code Bot commented May 17, 2026 •

Copy link
Copy Markdown
OBJ-80 M4.5 — Restore API (creates a new version)

Milestone: M4 · Wave: 2

Summary

Implement POST /api/documents/{id}/restore?version=N. Creates a NEW version whose body equals version N; never destructive.

Acceptance

  • New versionNumber = maxExisting + 1
  • Body equals version N body
  • Audit metadata records restoredFrom = N

Validation

  • DB check: after restore, SELECT version_number, body, restored_from FROM document_versions ORDER BY version_number DESC LIMIT 1 shows the expected row
  • Live API check: POST /api/documents/{id}/restore?version=1 → 200; subsequent GET /versions shows new version with restoredFrom=1
  • Script: scripts/validate-obj-NNN.ps1

Branch / PR

Branch from main; target main. No trailers/footer.

Review in Linear

@objectgyan
objectgyan merged commit b0d7a29 into main May 17, 2026
2 checks passed
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.

1 participant