Files
goclaw/internal/backup/preflight_sqlite.go
T
Duc Nguyen 52f48e5ea6 fix(backup): detect pg server major for version-aware pg_dump hints (#829) (#830)
* fix(backup): detect pg server major for version-aware pg_dump hints

pg_dump aborts when its major version is older than the server's, so
backup preflight now runs SHOW server_version_num against the live PG
server and uses the detected major to drive:

- the missing-pg_dump hint (names the exact postgresqlNN-client)
- a new compat check that flags an installed-but-too-old pg_dump as
  not-ready, instead of letting backup fail partway through the dump

Adds ParsePgDumpMajor helper for Debian/Homebrew/EDB output shapes,
covered by table-driven unit tests. Normalizes nil ctx once at
RunPreflight boundary so downstream exec.CommandContext calls are safe.
Stubs detectPGServerMajor + checkPgDumpServerCompat for the sqliteonly
build.

UI: removes the duplicate static hint from the preflight alert box so
the dynamic, actionable warning is the single source of truth. Drops
the obsolete pgDumpHint i18n key from en/vi/zh locale files.

Refs #829

* fix(docker): bump runtime base alpine 3.22 → 3.23

Alpine 3.23 main ships postgresql16-client, postgresql17-client, and
postgresql18-client simultaneously. Alpine 3.22 only shipped up to
postgresql17-client, so the backup preflight's dynamic hint to install
postgresql18-client previously failed with "no such package" on PG 18
deployments.

No client package is pre-bundled: the on-demand install via the
Packages page now resolves for any supported PG major.

Refs #829
2026-04-11 21:22:04 +07:00

47 lines
1.1 KiB
Go

//go:build sqliteonly
package backup
import (
"context"
"fmt"
"os"
)
// detectPGServerMajor is a no-op for SQLite builds; always returns 0 so
// RunPreflight falls back to a generic pg_dump hint.
func detectPGServerMajor(_ context.Context, _ string) int {
return 0
}
// checkPgDumpServerCompat is a no-op for SQLite builds (no pg_dump involved).
// Returns an empty check (Name=="") so RunPreflight skips appending it.
func checkPgDumpServerCompat(_ context.Context, _ int) (PreflightCheck, bool) {
return PreflightCheck{}, true
}
func checkDBSize(ctx context.Context, dsn string) (PreflightCheck, int64) {
dbPath := parseSQLitePath(dsn)
if dbPath == "" {
return PreflightCheck{
Name: "db_size",
Status: "warning",
Detail: "could not resolve SQLite database path",
}, 0
}
info, err := os.Stat(dbPath)
if err != nil {
return PreflightCheck{
Name: "db_size",
Status: "warning",
Detail: fmt.Sprintf("could not stat SQLite db: %v", err),
}, 0
}
return PreflightCheck{
Name: "db_size",
Status: "ok",
Detail: fmt.Sprintf("SQLite db %d MB", info.Size()>>20),
}, info.Size()
}