Optionally output database table sizes after migrations complete (#38620)

Resolves #35314.

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)

## Testing

- [x] QA'd all new/changed functionality manually
This commit is contained in:
Ian Littman
2026-01-26 17:55:55 -06:00
committed by GitHub
parent 5a550c1630
commit 72e55a4459
5 changed files with 59 additions and 0 deletions
+18
View File
@@ -2,6 +2,7 @@ package main
import (
"bufio"
"encoding/json"
"fmt"
"os"
@@ -29,6 +30,8 @@ To setup Fleet infrastructure, use one of the available commands.
noPrompt := false
// Whether to enable developer options
dev := false
// Whether to show table stats before and after the migration
showTableStats := false
dbCmd := &cobra.Command{
Use: "db",
@@ -68,6 +71,20 @@ To setup Fleet infrastructure, use one of the available commands.
}
}
if showTableStats {
defer func() {
stats, err := ds.GetTableRowCounts(cmd.Context())
if err != nil {
initFatal(err, "getting table stats")
}
statsAsJSON, err := json.Marshal(stats)
if err != nil {
initFatal(err, "encoding table row counts to JSON")
}
fmt.Printf("Table Row Counts: %s\n", statsAsJSON)
}()
}
switch status.StatusCode {
case fleet.NoMigrationsCompleted:
// OK
@@ -102,6 +119,7 @@ To setup Fleet infrastructure, use one of the available commands.
dbCmd.PersistentFlags().BoolVar(&noPrompt, "no-prompt", false, "disable prompting before migrations (for use in scripts)")
dbCmd.PersistentFlags().BoolVar(&dev, "dev", false, "Enable developer options")
dbCmd.PersistentFlags().BoolVar(&showTableStats, "with-table-stats", false, "Show approximate table row counts after migrations")
prepareCmd.AddCommand(dbCmd)
return prepareCmd