Skip to content

Commit

Permalink
fix: cli config fails (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley authored Apr 15, 2024
1 parent 9dffc47 commit a911f1f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
2 changes: 0 additions & 2 deletions backend/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ func main() {
configPath := flag.String("config", filepath.Join("..", "..", "config"), "Specify the path to the config directory")
useDevDotEnv := flag.Bool("use-dev-dot-env", true, "Specify if you want to use the .env.dev file")

fmt.Println("foo", *useDevDotEnv)

flag.Parse()

config, err := config.GetConfiguration(*configPath, *useDevDotEnv)
Expand Down
10 changes: 8 additions & 2 deletions cli/commands/clean_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/user"
"sync"

"github.com/GenerateNU/sac/backend/src/config"
_ "github.com/lib/pq"
"github.com/urfave/cli/v2"
)
Expand All @@ -32,7 +33,12 @@ func ClearDBCommand() *cli.Command {
func CleanTestDBs(ctx context.Context) error {
fmt.Println("Cleaning test databases")

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

db, err := sql.Open("postgres", config.Database.WithDb())
if err != nil {
return err
}
Expand All @@ -45,7 +51,7 @@ func CleanTestDBs(ctx context.Context) error {
}

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)
rows, err := db.Query(query, currentUser.Username, config.Database.DatabaseName)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cli/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commands
import (
"path/filepath"

"github.com/GenerateNU/sac/backend/src/config"
"github.com/GenerateNU/sac/cli/utils"
)

Expand All @@ -12,6 +11,6 @@ var (
FRONTEND_DIR = filepath.Join(ROOT_DIR, "/frontend")
BACKEND_DIR = filepath.Join(ROOT_DIR, "/backend")
BACKEND_SRC_DIR = filepath.Join(BACKEND_DIR, "/src")
CONFIG, _ = config.GetConfiguration(filepath.Join(ROOT_DIR, "/config"), false)
CONFIG = filepath.Join(ROOT_DIR, "/config")
MIGRATION_FILE = filepath.Join(BACKEND_SRC_DIR, "/migrations/data.sql")
)
15 changes: 13 additions & 2 deletions cli/commands/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"sync"

"github.com/GenerateNU/sac/backend/src/config"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -52,7 +53,12 @@ func DropData() error {
dbMutex.Lock()
defer dbMutex.Unlock()

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

db, err := sql.Open("postgres", config.Database.WithDb())
if err != nil {
return err
}
Expand Down Expand Up @@ -95,7 +101,12 @@ func DropDB() error {
dbMutex.Lock()
defer dbMutex.Unlock()

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

db, err := sql.Open("postgres", config.Database.WithDb())
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion cli/commands/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"

"github.com/GenerateNU/sac/backend/src/config"
"github.com/lib/pq"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -34,7 +35,12 @@ func InsertCommand() *cli.Command {
}

func InsertDB() error {
db, err := sql.Open("postgres", CONFIG.Database.WithDb())
config, err := config.GetConfiguration(CONFIG, false)
if err != nil {
return err
}

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

0 comments on commit a911f1f

Please sign in to comment.