fix: dumper should write output to DumpName#21
Conversation
WalkthroughRedirected gzip command output from standard output to a created file named by DumpName in both MySQL and PostgreSQL dump implementations. Added file creation, error handling, and deferred close. Updated .gitignore to include .idea/. No changes to exported/public APIs. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant Dump as Dump.Exec
participant DumpTool as [mysqldump/pg_dump]
participant Gzip as gzip
participant File as DumpName (.gz)
Caller->>Dump: Exec()
Dump->>DumpTool: start
DumpTool-->>Gzip: dump stdout (pipe)
Dump->>File: create DumpName
Gzip-->>File: write compressed bytes (stdout redirected)
DumpTool-->>Dump: exit
Gzip-->>Dump: exit
Dump-->>Caller: return
note over Dump,Gzip: stderr remains directed to os.Stderr
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
pkg/dbdump/postgres/postgres.go (1)
80-87: File creation and output redirection look correct.The implementation properly creates the output file, handles creation errors, and redirects gzip output to the file. The deferred close ensures cleanup even on early returns.
Consider checking the error from
f.Close()to catch potential write failures:- defer f.Close() + defer func() { + if closeErr := f.Close(); closeErr != nil && err == nil { + err = fmt.Errorf("failed to close dump file: %w", closeErr) + } + }()This would require naming the return value, but it's a minor improvement that can be deferred.
pkg/dbdump/mysql/mysql.go (1)
79-86: File creation and output redirection look correct.The implementation properly creates the output file, handles creation errors, and redirects gzip output to the file. The deferred close ensures cleanup even on early returns.
Two minor observations:
This code is duplicated in
pkg/dbdump/postgres/postgres.go(lines 80-87). Consider extracting the file creation and gzip stdout setup into a shared helper if more database types are added.Consider checking the error from
f.Close()to catch potential write failures:- defer f.Close() + defer func() { + if closeErr := f.Close(); closeErr != nil && err == nil { + err = fmt.Errorf("failed to close dump file: %w", closeErr) + } + }()Both suggestions can be deferred to future work.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.gitignore(1 hunks)pkg/dbdump/mysql/mysql.go(1 hunks)pkg/dbdump/postgres/postgres.go(1 hunks)
🔇 Additional comments (1)
.gitignore (1)
21-21: LGTM!Adding
.idea/to.gitignoreis appropriate for excluding JetBrains IDE configuration files from version control.
Summary by CodeRabbit
New Features
Chores