Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
package main

import (
"log"
"os"
"path/filepath"

"github.com/pgedge/ace/internal/cli"
"github.com/pgedge/ace/internal/logger"
"github.com/pgedge/ace/pkg/config"
)

Expand All @@ -25,18 +25,18 @@ func main() {
if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
execPath, err := os.Executable()
if err != nil {
log.Fatalf("unable to determine executable path: %v", err)
logger.Fatal("unable to determine executable path: %v", err)
}
root := filepath.Dir(filepath.Dir(execPath))
cfgPath = filepath.Join(root, "ace.yaml")
}
if err := config.Init(cfgPath); err != nil {
log.Fatalf("loading config (%s): %v", cfgPath, err)
logger.Fatal("loading config (%s): %v", cfgPath, err)
}

app := cli.SetupCLI()
err := app.Run(os.Args)
if err != nil {
log.Fatalf("Error: %v", err)
logger.Error("%v", err)
}
}
37 changes: 14 additions & 23 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TableDiffCLI(ctx *cli.Context) error {
blockSizeStr := ctx.String("block-size")
blockSizeInt, err := strconv.ParseInt(blockSizeStr, 10, 64)
if err != nil {
return fmt.Errorf("invalid block size '%s': %v", blockSizeStr, err)
return fmt.Errorf("invalid block size '%s': %w", blockSizeStr, err)
}

task := core.NewTableDiffTask()
Expand All @@ -326,18 +326,17 @@ func TableDiffCLI(ctx *cli.Context) error {
task.OverrideBlockSize = ctx.Bool("override-block-size")

if err := task.Validate(); err != nil {
return fmt.Errorf("validation failed: %v", err)
return fmt.Errorf("validation failed: %w", err)
}

if err := task.RunChecks(true); err != nil {
return fmt.Errorf("checks failed: %v", err)
return fmt.Errorf("checks failed: %w", err)
}

if err := task.ExecuteTask(); err != nil {
return fmt.Errorf("error during comparison: %v", err)
return fmt.Errorf("error during comparison: %w", err)
}

fmt.Println("Table diff completed")
return nil
}

Expand All @@ -352,10 +351,9 @@ func TableRerunCLI(ctx *cli.Context) error {
task.QuietMode = ctx.Bool("quiet")

if err := task.ExecuteRerunTask(); err != nil {
return fmt.Errorf("error during table-rerun: %v", err)
return fmt.Errorf("error during table-rerun: %w", err)
}

fmt.Println("Table rerun completed")
return nil
}

Expand All @@ -378,14 +376,13 @@ func TableRepairCLI(ctx *cli.Context) error {
task.GenerateReport = ctx.Bool("generate-report")

if err := task.ValidateAndPrepare(); err != nil {
return fmt.Errorf("validation failed: %v", err)
return fmt.Errorf("validation failed: %w", err)
}

if err := task.Run(true); err != nil {
return fmt.Errorf("error during table repair: %v", err)
return fmt.Errorf("error during table repair: %w", err)
}

fmt.Println("Table repair complete")
return nil
}

Expand All @@ -397,26 +394,24 @@ func SpockDiffCLI(ctx *cli.Context) error {
task.Output = ctx.String("output")

if err := task.Validate(); err != nil {
return fmt.Errorf("validation failed: %v", err)
return fmt.Errorf("validation failed: %w", err)
}

if err := task.RunChecks(true); err != nil {
return fmt.Errorf("checks failed: %v", err)
return fmt.Errorf("checks failed: %w", err)
}

if err := task.ExecuteTask(); err != nil {
return fmt.Errorf("error during spock diff: %v", err)
return fmt.Errorf("error during spock diff: %w", err)
}

fmt.Println("Spock diff completed")
return nil
}

func SchemaDiffCLI(ctx *cli.Context) error {
blockSizeStr := ctx.String("block-size")
blockSizeInt, err := strconv.ParseInt(blockSizeStr, 10, 64)
if err != nil {
return fmt.Errorf("invalid block size '%s': %v", blockSizeStr, err)
return fmt.Errorf("invalid block size '%s': %w", blockSizeStr, err)
}

task := &core.SchemaDiffCmd{
Expand All @@ -437,18 +432,16 @@ func SchemaDiffCLI(ctx *cli.Context) error {
task.OverrideBlockSize = ctx.Bool("override-block-size")

if err := core.SchemaDiff(task); err != nil {
return fmt.Errorf("error during schema diff: %v", err)
return fmt.Errorf("error during schema diff: %w", err)
}

fmt.Println("Schema diff completed")
return nil
}

func RepsetDiffCLI(ctx *cli.Context) error {
blockSizeStr := ctx.String("block-size")
blockSizeInt, err := strconv.ParseInt(blockSizeStr, 10, 64)
if err != nil {
return fmt.Errorf("invalid block size '%s': %v", blockSizeStr, err)
return fmt.Errorf("invalid block size '%s': %w", blockSizeStr, err)
}

task := &core.RepsetDiffCmd{
Expand All @@ -468,9 +461,7 @@ func RepsetDiffCLI(ctx *cli.Context) error {
task.OverrideBlockSize = ctx.Bool("override-block-size")

if err := core.RepsetDiff(task); err != nil {
return fmt.Errorf("error during repset diff: %v", err)
return fmt.Errorf("error during repset diff: %w", err)
}

fmt.Println("Repset diff completed")
return nil
}
12 changes: 6 additions & 6 deletions internal/core/repset_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"bufio"
"context"
"fmt"
"log"
"maps"
"os"
"strconv"
Expand All @@ -25,6 +24,7 @@ import (
"github.com/jackc/pgx/v4/pgxpool"
"github.com/pgedge/ace/db/queries"
"github.com/pgedge/ace/internal/auth"
"github.com/pgedge/ace/internal/logger"
"github.com/pgedge/ace/pkg/types"
)

Expand Down Expand Up @@ -164,7 +164,7 @@ func RepsetDiff(task *RepsetDiffCmd) error {
for _, skip := range task.skipTablesList {
if strings.TrimSpace(skip) == tableName {
if !task.Quiet {
fmt.Printf("Skipping table: %s\n", tableName)
logger.Info("Skipping table: %s", tableName)
}
skipped = true
break
Expand All @@ -175,7 +175,7 @@ func RepsetDiff(task *RepsetDiffCmd) error {
}

if !task.Quiet {
fmt.Printf("Diffing table: %s\n", tableName)
logger.Info("Diffing table: %s", tableName)
}

tdTask := NewTableDiffTask()
Expand All @@ -192,16 +192,16 @@ func RepsetDiff(task *RepsetDiffCmd) error {
tdTask.QuietMode = task.Quiet

if err := tdTask.Validate(); err != nil {
log.Printf("validation for table %s failed: %v", tableName, err)
logger.Warn("validation for table %s failed: %v", tableName, err)
continue
}

if err := tdTask.RunChecks(true); err != nil {
log.Printf("checks for table %s failed: %v", tableName, err)
logger.Warn("checks for table %s failed: %v", tableName, err)
continue
}
if err := tdTask.ExecuteTask(); err != nil {
log.Printf("error during comparison for table %s: %v", tableName, err)
logger.Warn("error during comparison for table %s: %v", tableName, err)
continue
}
}
Expand Down
14 changes: 7 additions & 7 deletions internal/core/schema_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"maps"
"sort"
"strconv"
Expand All @@ -24,6 +23,7 @@ import (
"github.com/jackc/pgx/v4/pgxpool"
"github.com/pgedge/ace/db/queries"
"github.com/pgedge/ace/internal/auth"
"github.com/pgedge/ace/internal/logger"
"github.com/pgedge/ace/pkg/types"
)

Expand Down Expand Up @@ -273,15 +273,15 @@ func schemaDDLDiff(task *SchemaDiffCmd) error {

pool, err := auth.GetClusterNodeConnection(nodeWithDBInfo, "")
if err != nil {
log.Printf("could not connect to node %s: %v. Skipping.", nodeName, err)
logger.Warn("could not connect to node %s: %v. Skipping.", nodeName, err)
continue
}
defer pool.Close()

db := queries.NewQuerier(pool)
objects, err := getObjectsForSchema(db, task.SchemaName)
if err != nil {
log.Printf("could not get schema objects for node %s: %v. Skipping.", nodeName, err)
logger.Warn("could not get schema objects for node %s: %v. Skipping.", nodeName, err)
continue
}

Expand Down Expand Up @@ -370,7 +370,7 @@ func SchemaDiff(task *SchemaDiffCmd) error {
for _, tableName := range task.tableList {
qualifiedTableName := fmt.Sprintf("%s.%s", task.SchemaName, tableName)
if !task.Quiet {
fmt.Printf("Diffing table: %s\n", qualifiedTableName)
logger.Info("Diffing table: %s", qualifiedTableName)
}

tdTask := NewTableDiffTask()
Expand All @@ -387,16 +387,16 @@ func SchemaDiff(task *SchemaDiffCmd) error {
tdTask.QuietMode = task.Quiet

if err := tdTask.Validate(); err != nil {
log.Printf("validation for table %s failed: %v", qualifiedTableName, err)
logger.Warn("validation for table %s failed: %v", qualifiedTableName, err)
continue
}

if err := tdTask.RunChecks(true); err != nil {
log.Printf("checks for table %s failed: %v", qualifiedTableName, err)
logger.Warn("checks for table %s failed: %v", qualifiedTableName, err)
continue
}
if err := tdTask.ExecuteTask(); err != nil {
log.Printf("error during comparison for table %s: %v", qualifiedTableName, err)
logger.Warn("error during comparison for table %s: %v", qualifiedTableName, err)
continue
}

Expand Down
Loading