From f5cf570fd31822a98f379d7d8430a17bde6129af Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 10 Oct 2014 14:19:35 +0300 Subject: [PATCH] better transaction handling --- engine/storage_sql.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engine/storage_sql.go b/engine/storage_sql.go index e7f5f5cf5..690b19d79 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -216,11 +216,15 @@ func (self *SQLStorage) SetTPDestination(tpid string, dest *Destination) error { tx := self.db.Begin() tx.Where("tpid = ?", tpid).Where("id = ?", dest.Id).Delete(TpDestination{}) for _, prefix := range dest.Prefixes { - tx.Save(TpDestination{ + db := tx.Save(TpDestination{ Tpid: tpid, Id: dest.Id, Prefix: prefix, }) + if db.Error != nil { + tx.Rollback() + return db.Error + } } tx.Commit() return nil