diff options
author | xengineering <me@xengineering.eu> | 2024-05-09 21:10:15 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-05-09 21:10:50 +0200 |
commit | 2db08f564ddb38e80c79c9338047f4e8f3a977e8 (patch) | |
tree | a54421ecb885d59b66d143986f51717127811ac8 | |
parent | a2aa866e630c45e1db4fadbb20cb1a9d24384a79 (diff) | |
download | ceres-2db08f564ddb38e80c79c9338047f4e8f3a977e8.tar ceres-2db08f564ddb38e80c79c9338047f4e8f3a977e8.tar.zst ceres-2db08f564ddb38e80c79c9338047f4e8f3a977e8.zip |
model: Wrap migration completely in transaction
This makes it more clear that the full migration will be rolled back on
errors.
-rw-r--r-- | model/database.go | 13 |
1 files changed, 6 insertions, 7 deletions
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 } |