Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
DOOduneye committed Mar 3, 2024
1 parent 8927372 commit 6889530
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 59 deletions.
34 changes: 17 additions & 17 deletions cli/commands/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ import (
)

var backendCmd = &cli.Command{

Check failure on line 12 in cli/commands/backend.go

View workflow job for this annotation

GitHub Actions / Lint

var `backendCmd` is unused (unused)
Name: "backend",
Usage: "Starts the backend server in development mode",
Action: func(c *cli.Context) error {
cmd := exec.Command("go", "run", "backend/main.go", "--use-dev-dot-env")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return fmt.Errorf("error starting backend: %w", err)
}
return nil
},
Name: "backend",
Usage: "Starts the backend server in development mode",
Action: func(c *cli.Context) error {
cmd := exec.Command("go", "run", "backend/main.go", "--use-dev-dot-env")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return fmt.Errorf("error starting backend: %w", err)
}
return nil
},
}

func BackendCommand() *cli.Command {
command := &cli.Command{
Name: "backend",
Usage: "Starts the backend server",
Name: "backend",
Usage: "Starts the backend server",
Aliases: []string{"be"},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "use-dev-dot-env",
Usage: "Use the .env file in the backend directory",
Name: "use-dev-dot-env",
Usage: "Use the .env file in the backend directory",
Aliases: []string{"d"},
},
},
Expand All @@ -56,4 +56,4 @@ func RunBackend() error {
return fmt.Errorf("error starting backend: %w", err)
}
return nil
}
}
84 changes: 42 additions & 42 deletions cli/commands/clean_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,62 +34,62 @@ func ClearDBCommand() *cli.Command {
}

func CleanTestDBs() error {
fmt.Println("Cleaning test databases")
fmt.Println("Cleaning test databases")

db, err := sql.Open("postgres", CONFIG.Database.WithDb())
if err != nil {
return err
}
db, err := sql.Open("postgres", CONFIG.Database.WithDb())
if err != nil {
return err
}

defer db.Close()
defer db.Close()

currentUser, err := user.Current()
if err != nil {
return fmt.Errorf("failed to get current user: %w", err)
}
currentUser, err := user.Current()
if err != nil {
return fmt.Errorf("failed to get current user: %w", err)
}

query := "SELECT datname FROM pg_database WHERE datistemplate = false AND datname != 'postgres' AND datname != $1 AND datname != $2 AND datname LIKE 'sac_test_%';"
rows, err := db.Query(query, currentUser.Username, CONFIG.Database.DatabaseName)
if err != nil {
return err
}
query := "SELECT datname FROM pg_database WHERE datistemplate = false AND datname != 'postgres' AND datname != $1 AND datname != $2 AND datname LIKE 'sac_test_%';"
rows, err := db.Query(query, currentUser.Username, CONFIG.Database.DatabaseName)
if err != nil {
return err
}

defer rows.Close()
defer rows.Close()

var wg sync.WaitGroup
var dropped, failed int
var wg sync.WaitGroup
var dropped, failed int

for rows.Next() {
var dbName string
for rows.Next() {
var dbName string

if err := rows.Scan(&dbName); err != nil {
return err
}
if err := rows.Scan(&dbName); err != nil {
return err
}

wg.Add(1)
wg.Add(1)

go func(dbName string) {
defer wg.Done()
go func(dbName string) {
defer wg.Done()

fmt.Printf("Dropping database %s\n", dbName)
fmt.Printf("Dropping database %s\n", dbName)

_, err := db.Exec(fmt.Sprintf("DROP DATABASE %s", dbName))
if err != nil {
fmt.Printf("Failed to drop database %s: %v\n", dbName, err)
failed++
} else {
dropped++
}
}(dbName)
}
_, err := db.Exec(fmt.Sprintf("DROP DATABASE %s", dbName))
if err != nil {
fmt.Printf("Failed to drop database %s: %v\n", dbName, err)
failed++
} else {
dropped++
}
}(dbName)
}

wg.Wait()
wg.Wait()

fmt.Printf("\nSummary:\n - Databases dropped: %d\n - Databases failed to drop: %d\n", dropped, failed)
fmt.Printf("\nSummary:\n - Databases dropped: %d\n - Databases failed to drop: %d\n", dropped, failed)

if failed > 0 {
return fmt.Errorf("failed to drop %d database(s)", failed)
}
if failed > 0 {
return fmt.Errorf("failed to drop %d database(s)", failed)
}

return nil
return nil
}

0 comments on commit 6889530

Please sign in to comment.