Skip to content

refactor(project): move dump logic into internal packages - #1358

Open
Soner (shyim) wants to merge 1 commit into
feat/dump-table-limitfrom
refactor/dump-command
Open

refactor(project): move dump logic into internal packages#1358
Soner (shyim) wants to merge 1 commit into
feat/dump-table-limitfrom
refactor/dump-command

Conversation

@shyim

@shyim Soner (shyim) commented Aug 12, 2026

Copy link
Copy Markdown
Member

What changed?

Refactors the project dump command: cmd/project/project_dump.go held nearly all logic inline in its RunE (255 lines). The logic now lives in internal packages, following the thin-command convention used by project sbom and project create:

  • internal/shop/dump.go — new shop.DumpDatabase(ctx, sqlCfg, cfg, opts) entry point with a DumpDatabaseOptions struct. Owns config mutation (--clean/--anonymize/--limit overrides/faker normalization), the ConfigDumpmysqldump.Dumper mapping, and the dump run.
  • internal/mysqldump/output.go — new typed Compression string (CompressionNone/CompressionGzip/CompressionZstd) with ParseCompression for the flag boundary, and OpenOutput, which layers the compressor over the output file behind a single io.WriteCloser (replaces the previous w.(*zstd.Encoder)/w.(*gzip.Writer) type assertions).
  • cmd/project/project_dump.go shrinks to 151 lines; RunE is now flag reading plus one delegation call. Only genuine CLI concerns remain: flag registration, connection resolution, and the interactive password prompt.
  • Deletes the unused mysqldump.Config/NewConfig/ConnectionString (dead code).

Deliberate behavior changes:

  1. The *sql.DB, the output file, and the compression writer are now always closed, including on error paths. Previously all three leaked, and a failed compressor flush could silently truncate a dump — Close errors are now reported.
  2. An unknown --compression value is now a hard error (unsupported compression "bogus" (supported: gzip, zstd)); previously it silently produced an uncompressed dump without a suffix.

CLI flags and their behavior are otherwise unchanged.

Why?

The repo convention is thin cobra wrappers delegating to internal packages (no cobra imports under internal/). Having the dump orchestration inline made it untestable without cobra scaffolding and mixed CLI concerns with dump logic. The move also surfaced and fixed the resource-leak bugs listed above.

How was this tested?

  • New unit tests: internal/mysqldump/output_test.go (compression parsing, gzip/zstd round-trips, stdout never closed) and internal/shop/dump_test.go (limit-override parsing and validation, YAML order_by preserved when --limit overrides rows).
  • Existing assembleConnectionURI tests pass unchanged.
  • go test ./... and golangci-lint run pass; manually verified --compression bogus now errors.

Related issue or discussion

Stacked on #1357.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1ccbe989-11af-4cae-80e8-ff7770de606a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@shyim
Soner (shyim) force-pushed the refactor/dump-command branch from e448a2b to 58e7f96 Compare August 12, 2026 06:22
@shyim
Soner (shyim) marked this pull request as ready for review August 12, 2026 06:25
The dump command's RunE held nearly all logic inline: DB opening, config
mutation, --limit parsing, output/compression writer setup and error
rewriting. Move the orchestration into shop.DumpDatabase with an options
struct and the compression/output handling into mysqldump (typed
Compression string with ParseCompression, OpenOutput), following the
thin-command convention used by project sbom and project create.

Behavior changes: the sql.DB, the output file and the compressor are now
always closed (previously leaked), and an unknown --compression value is
now an error instead of silently producing an uncompressed dump. Also
removes the unused mysqldump.Config.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@shyim
Soner (shyim) force-pushed the refactor/dump-command branch from 58e7f96 to 23d4ef3 Compare August 13, 2026 08:52
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