From a60805fccfcaf0454cf235565687e921ad7cc2c2 Mon Sep 17 00:00:00 2001 From: soxx Date: Fri, 14 Jun 2024 12:06:58 +0200 Subject: [PATCH] feat(postgres): added console debug option --- pkg/database/postgres.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/database/postgres.go b/pkg/database/postgres.go index f1d8402..e4ee38a 100644 --- a/pkg/database/postgres.go +++ b/pkg/database/postgres.go @@ -5,7 +5,6 @@ import ( "database/sql" "embed" "fmt" - "git.dragse.it/anthrove/otter-space-sdk/internal/postgres" "git.dragse.it/anthrove/otter-space-sdk/internal/utils" "git.dragse.it/anthrove/otter-space-sdk/pkg/models" @@ -21,12 +20,14 @@ import ( var embedMigrations embed.FS type postgresqlConnection struct { - db *gorm.DB + db *gorm.DB + debug bool } -func NewPostgresqlConnection() OtterSpace { +func NewPostgresqlConnection(debugOutput bool) OtterSpace { return &postgresqlConnection{ - db: nil, + db: nil, + debug: debugOutput, } } @@ -170,12 +171,15 @@ func (p *postgresqlConnection) migrateDatabase(connectionString string) error { if err != nil { return fmt.Errorf("postgres migration: %v", err) } - if n != 0 { - log.Tracef("postgres migration: applied %d migrations!", n) - } else { - log.Trace("postgres migration: nothing to migrate") + if p.debug { + if n != 0 { + log.Infof("postgres migration: applied %d migrations!", n) + } else { + log.Info("postgres migration: nothing to migrate") + + } } return nil