diff --git a/backend/src/main.go b/backend/src/main.go index 490404ff7..3a06ad1c3 100644 --- a/backend/src/main.go +++ b/backend/src/main.go @@ -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) diff --git a/cli/commands/clean_tests.go b/cli/commands/clean_tests.go index a3923ce53..edc7955bd 100644 --- a/cli/commands/clean_tests.go +++ b/cli/commands/clean_tests.go @@ -7,6 +7,7 @@ import ( "os/user" "sync" + "github.com/GenerateNU/sac/backend/src/config" _ "github.com/lib/pq" "github.com/urfave/cli/v2" ) @@ -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 } @@ -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 } diff --git a/cli/commands/config.go b/cli/commands/config.go index e33a7f4ab..b7bb45e1a 100644 --- a/cli/commands/config.go +++ b/cli/commands/config.go @@ -3,7 +3,6 @@ package commands import ( "path/filepath" - "github.com/GenerateNU/sac/backend/src/config" "github.com/GenerateNU/sac/cli/utils" ) @@ -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") ) diff --git a/cli/commands/drop.go b/cli/commands/drop.go index 3a34f1ae1..37d90980e 100644 --- a/cli/commands/drop.go +++ b/cli/commands/drop.go @@ -5,6 +5,7 @@ import ( "fmt" "sync" + "github.com/GenerateNU/sac/backend/src/config" "github.com/urfave/cli/v2" ) @@ -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 } @@ -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 } diff --git a/cli/commands/insert.go b/cli/commands/insert.go index afbf4dec8..b3d40eb1c 100644 --- a/cli/commands/insert.go +++ b/cli/commands/insert.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" + "github.com/GenerateNU/sac/backend/src/config" "github.com/lib/pq" "github.com/urfave/cli/v2" ) @@ -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 }