Conversation
Save a snapshot of the post before each update so users can view previous versions and roll back to them. - Add PostRevision model (blog/revision.go) storing title, slug, content, draft status, and post type for each revision - Save a revision in UpdatePost before applying changes - Add GET /api/v1/posts/:id/revisions to list revisions - Add POST /api/v1/posts/:id/revisions/:revisionId/rollback to restore a previous version (saves current state as a new revision first, so rollbacks are always reversible) - Add revision history section to post-admin.html with AJAX loading - Add rollbackRevision JS function with confirmation dialog - Add tests for listing revisions, rollback, and auth checks Closes #163 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds post revision history functionality, allowing admins to view and roll back to previous versions of a post. Each time a post is updated, a snapshot of its pre-edit state is saved as a PostRevision. The admin post editor displays a revision history table and provides a "Restore" action that saves the current state before applying the old version.
Changes:
- New
PostRevisionmodel and two admin API endpoints (ListRevisions,RollbackRevision) with corresponding route registration and DB migration - Frontend revision history UI in the admin post editor, loaded via AJAX with a rollback function
- Test coverage for listing revisions, rollback, auth checks, and invalid revision ID
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
blog/revision.go |
New PostRevision GORM model to store post snapshots |
tools/migrate.go |
Adds PostRevision to the AutoMigrate call |
admin/admin.go |
Saves revision in UpdatePost; adds ListRevisions and RollbackRevision handlers |
goblog.go |
Registers GET and POST routes for revision listing and rollback |
templates/post-admin.html |
Adds revision history section with AJAX loading and restore links |
www/js/admin-script.js |
Adds rollbackRevision() function with confirmation dialog |
admin/admin_test.go |
Tests for revision listing, rollback, auth checks, and 404 on bad revision ID |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Skip creating a revision when nothing has changed (compare title, slug, content, draft, post_type_id before saving) - Add doc comment to PostRevision struct - Add .fail() handler to revisions AJAX call for error feedback - Wrap rollback in a transaction with error handling so save-revision and apply-revision are atomic Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Use gorm:"type:text" instead of legacy sql:"type:text;" on Content - Remove redundant safeSlug() in change detection since slug is already normalized earlier - Add missing trailing newline to admin-script.js Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Gin can't have different wildcard names (:id vs :yyyy) at the same path segment. Move revision routes from /api/v1/posts/:id/revisions to /api/v1/revisions/:id to avoid conflicting with the existing /api/v1/posts/:yyyy/:mm/:dd/:slug route. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the ability to view and roll back to previous versions of a post.
How it works
PostRevisionsnapshot is saved with the pre-edit state (title, slug, content, draft, post type)Changes
blog/revision.goPostRevisionmodeltools/migrate.goPostRevisiontoAutoMigrateadmin/admin.goUpdatePost; addListRevisionsandRollbackRevisionhandlersgoblog.goGET /api/v1/posts/:id/revisionsandPOST /api/v1/posts/:id/revisions/:revisionId/rollbacktemplates/post-admin.htmlwww/js/admin-script.jsrollbackRevision()functionadmin/admin_test.goDesign decisions
onfocusout), which may create many revisions. If this becomes noisy, a future enhancement could skip revisions where content is identical.Closes #163
Test plan
🤖 Generated with Claude Code