From 8d13e8e61b1c97ee8856cc37ff873999f7d4215d Mon Sep 17 00:00:00 2001
From: sausin <sausin@users.noreply.github.com>
Date: Wed, 15 Apr 2020 17:26:23 +0530
Subject: [PATCH] Add transactions (#16)

* Add transactions

If there is any failure in database, leave the database without any changes.

* Update UpdateAttribute.php

* Update UpdateAttribute.php

* Apply fixes from StyleCI (#17)
---
 src/UpdateAttribute.php | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/UpdateAttribute.php b/src/UpdateAttribute.php
index 050a866..8692438 100644
--- a/src/UpdateAttribute.php
+++ b/src/UpdateAttribute.php
@@ -13,7 +13,11 @@ protected function updateAutoIncrement($driver, $table): void
     {
         $method = "update{$driver}AutoIncrement";
 
-        $this->{$method}($table);
+        // perform changes as a transaction to avoid
+        // borking the database in case of issues.
+        DB::transaction(function () use ($method, $table) {
+            $this->{$method}($table);
+        });
     }
 
     protected function updateMysqlAutoIncrement($table): void