feat(cli): add URL prefix fix command - #1600
Open
Octobug wants to merge 1 commit into
Open
Conversation
closes apache#861 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a new answer fix CLI command to rewrite stored URL prefixes across branding assets, user avatars, and post content (including revisions and file records), with support for dry-run and a global row limit. This fits into the codebase as an administrative maintenance tool for safely migrating stored paths (e.g., /uploads/ → /cdn/) while Answer is stopped.
Changes:
- Introduces URL-prefix classification and batched DB rewrite logic for branding, avatars, posts/revisions, and
file_recordURLs. - Adds cache invalidation for branding site-info when using file-backed cache storage.
- Wires a new Cobra command (
answer fix ...) with--dry-runand--limitflags.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/cli/fix.go | Core fix orchestration, prefix classification/replacement utilities, batching, and summary output. |
| internal/cli/fix_post.go | Applies prefix fixes to question/answer bodies, revisions, and post-related file records. |
| internal/cli/fix_filerecord.go | Updates file_record.file_url for selected sources. |
| internal/cli/fix_cache.go | Invalidates branding site-info cache in file-backed memory cache. |
| internal/cli/fix_branding.go | Fixes branding JSON fields in site_info and related branding file records. |
| internal/cli/fix_avatar.go | Fixes custom avatar URLs in user avatar JSON and related avatar file records. |
| cmd/command.go | Adds the fix command and its flags to the CLI. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+74
to
+76
| if err := json.Unmarshal([]byte(user.Avatar), avatar); err != nil { | ||
| return nil | ||
| } |
Comment on lines
+164
to
+175
| switch classifyText(texts, opts.SrcPrefix, opts.DstPrefix, markers) { | ||
| case matchBoth: | ||
| fmt.Printf("[%s] WARN %s: has BOTH prefixes, skipping (manual fix needed)\n", label, target) | ||
| result.Skipped++ | ||
| return nil | ||
| case matchSkip: | ||
| fmt.Printf("[%s] skip %s: already has DST_PREFIX\n", label, target) | ||
| result.Skipped++ | ||
| return nil | ||
| case matchNone: | ||
| return nil | ||
| } |
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.
I've tested locally with fake data generated in sqlite db, including:
It took about 10 minutes to complete the fixing.