diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/database.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/model/database.go b/model/database.go index 8b66bb5..d6d6c16 100644 --- a/model/database.go +++ b/model/database.go @@ -4,7 +4,6 @@ import ( "database/sql" "embed" "log" - "fmt" _ "github.com/mattn/go-sqlite3" ) @@ -40,15 +39,19 @@ func ConnectDatabase(path string) { func Transaction(f func(*sql.Tx) error) error { tx, err := db.Begin() if err != nil { + log.Printf("Failed to start database transaction: %v", err) return err } + defer func() { + if tx.Rollback() == nil { + log.Println("Rolled back transaction") + } + }() err = f(tx) if err != nil { - rollbackErr := tx.Rollback() - if rollbackErr != nil { - return fmt.Errorf("Failed rollback '%w' after failed transaction '%w'", rollbackErr, err) - } + log.Printf("Failed transaction: %v", err) + return err } return tx.Commit() @@ -68,7 +71,7 @@ func MigrateDatabase() { return nil }) if err != nil { - log.Fatalf("Migration failed: %v\n", err) + log.Fatalf("Fatal: Database migration failed") } } |