Files
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

105 lines
3.2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package commands
import (
"context"
"fmt"
"github.com/hashicorp/go-multierror"
"github.com/hanzoteam/server/server/v8/cmd/mmctl/client"
"github.com/hanzoteam/server/server/v8/cmd/mmctl/printer"
"github.com/hanzoteam/server/server/public/model"
"github.com/spf13/cobra"
)
var IntegrityCmd = &cobra.Command{
Use: "integrity",
Short: "Check database records integrity.",
Long: "Perform a relational integrity check which returns information about any orphaned record found.",
Args: cobra.NoArgs,
PreRun: localOnlyPrecheck,
RunE: withClient(integrityCmdF),
}
func init() {
IntegrityCmd.Flags().Bool("confirm", false, "Confirm you really want to run a complete integrity check that may temporarily harm system performance")
IntegrityCmd.Flags().BoolP("verbose", "v", false, "Show detailed information on integrity check results")
RootCmd.AddCommand(IntegrityCmd)
}
func printRelationalIntegrityCheckResult(data model.RelationalIntegrityCheckData, verbose bool) {
printer.PrintT("Found {{len .Records}} in relation {{ .ChildName }} orphans of relation {{ .ParentName }}", data)
if !verbose {
return
}
const null = "NULL"
const empty = "empty"
for _, record := range data.Records {
var parentID string
switch {
case record.ParentId == nil:
parentID = null
case *record.ParentId == "":
parentID = empty
default:
parentID = *record.ParentId
}
if record.ChildId != nil {
if parentID == null || parentID == empty {
fmt.Printf(" Child %s (%s.%s) has %s ParentIdAttr (%s.%s)\n", *record.ChildId, data.ChildName, data.ChildIdAttr, parentID, data.ChildName, data.ParentIdAttr)
} else {
fmt.Printf(" Child %s (%s.%s) is missing Parent %s (%s.%s)\n", *record.ChildId, data.ChildName, data.ChildIdAttr, parentID, data.ChildName, data.ParentIdAttr)
}
} else {
if parentID == null || parentID == empty {
fmt.Printf(" Child has %s ParentIdAttr (%s.%s)\n", parentID, data.ChildName, data.ParentIdAttr)
} else {
fmt.Printf(" Child is missing Parent %s (%s.%s)\n", parentID, data.ChildName, data.ParentIdAttr)
}
}
}
}
func printIntegrityCheckResult(result model.IntegrityCheckResult, verbose bool) {
switch data := result.Data.(type) {
case model.RelationalIntegrityCheckData:
printRelationalIntegrityCheckResult(data, verbose)
default:
printer.PrintError("invalid data type")
}
}
func integrityCmdF(c client.Client, command *cobra.Command, args []string) error {
confirmFlag, _ := command.Flags().GetBool("confirm")
if !confirmFlag {
if err := getConfirmation("This check may harm performance on live systems. Are you sure you want to proceed?", false); err != nil {
return err
}
}
verboseFlag, _ := command.Flags().GetBool("verbose")
results, _, err := c.CheckIntegrity(context.TODO())
if err != nil {
return fmt.Errorf("unable to perform integrity check. Error: %w", err)
}
var errs *multierror.Error
for _, result := range results {
if result.Err != nil {
errs = multierror.Append(errs, result.Err)
printer.PrintError(result.Err.Error())
continue
}
printIntegrityCheckResult(result, verboseFlag)
}
return errs.ErrorOrNil()
}