From 2db08f564ddb38e80c79c9338047f4e8f3a977e8 Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 9 May 2024 21:10:15 +0200 Subject: model: Wrap migration completely in transaction This makes it more clear that the full migration will be rolled back on errors. --- model/database.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'model') diff --git a/model/database.go b/model/database.go index d6d6c16..3953c92 100644 --- a/model/database.go +++ b/model/database.go @@ -58,13 +58,12 @@ func Transaction(f func(*sql.Tx) error) error { } func MigrateDatabase() { - query, err := GetSql(`migrate`) - if err != nil { - log.Fatal(err) - } - - err = Transaction(func(tx *sql.Tx) error { - _, err := tx.Exec(query) + err := Transaction(func(tx *sql.Tx) error { + query, err := GetSql(`migrate`) + if err != nil { + log.Fatal(err) + } + _, err = tx.Exec(query) if err != nil { return err } -- cgit v1.2.3-70-g09d2