Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reads db url from config if not in env #478

Merged
merged 1 commit into from
Jan 9, 2025
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
2 changes: 1 addition & 1 deletion cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
log.Fatalf("Config error: %s", err)
}

err = initializeAppFunc()
err = initializeAppFunc(cfg)
if err != nil {
log.Fatalf("App init error: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/app/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMainFunction(_ *testing.T) { //nolint:paralleltest // cannot have simul
return &config.Config{HTTP: config.HTTP{Port: "8080"}, App: config.App{EncryptionKey: "test"}}, nil
}

initializeAppFunc = func() error {
initializeAppFunc = func(_ *config.Config) error {
return nil
}

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func NewConfig() (*Config, error) {
},
DB: DB{
PoolMax: 2,
URL: "",
},
EA: EA{
URL: "http://localhost:8000",
Expand Down
1 change: 1 addition & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ logger:

postgres:
pool_max: 5
url: ""

ea:
url: "http://localhost:8000"
Expand Down
7 changes: 4 additions & 3 deletions internal/app/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/golang-migrate/migrate/v4/source"
_ "github.com/golang-migrate/migrate/v4/source/file" // for file source
"github.com/golang-migrate/migrate/v4/source/iofs"
"github.com/open-amt-cloud-toolkit/console/config"
_ "modernc.org/sqlite" // sqlite3 driver
)

Expand All @@ -35,9 +36,9 @@ func MigrationError(op string) error {
return fmt.Errorf("%w: %s", errMigrate, op)
}

func Init() error {
databaseURL, ok := os.LookupEnv("DB_URL")
if !ok || databaseURL == "" {
func Init(cfg *config.Config) error {
databaseURL := cfg.DB.URL
if databaseURL == "" {
log.Printf("migrate: environment variable not declared: DB_URL -- using embedded database")
}

Expand Down
Loading