From a6f24cf3b12f3187a606bd2b70e7f6c439fb3a79 Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Tue, 1 May 2018 13:09:47 +0300 Subject: [PATCH] v1.2.0 update column issue --- app/Listeners/Updates/Version120.php | 28 ++++++++++++++ ...nge_quantity_column_invoice_bill_items.php | 38 ------------------- 2 files changed, 28 insertions(+), 38 deletions(-) delete mode 100644 database/migrations/2018_04_30_000000_change_quantity_column_invoice_bill_items.php diff --git a/app/Listeners/Updates/Version120.php b/app/Listeners/Updates/Version120.php index 3ee1329a1..eed244fe3 100644 --- a/app/Listeners/Updates/Version120.php +++ b/app/Listeners/Updates/Version120.php @@ -9,6 +9,8 @@ use App\Models\Company\Company; use App\Models\Expense\Bill; use App\Models\Income\Invoice; use App\Models\Setting\Category; +use DB; +use Schema; use Artisan; class Version120 extends Listener @@ -36,6 +38,8 @@ class Version120 extends Listener Artisan::call('migrate', ['--force' => true]); $this->updateInvoicesAndBills(); + + $this->changeQuantityColumn(); } protected function updatePermissions() @@ -106,4 +110,28 @@ class Version120 extends Listener } } } + + protected function changeQuantityColumn() + { + $connection = env('DB_CONNECTION'); + + if ($connection == 'mysql') { + $tables = [ + env('DB_PREFIX') . 'invoice_items', + env('DB_PREFIX') . 'bill_items' + ]; + + foreach ($tables as $table) { + DB::statement("ALTER TABLE `$table` MODIFY `quantity` DOUBLE(7,2) NOT NULL"); + } + } else { + Schema::table('invoice_items', function ($table) { + $table->decimal('quantity', 7, 2)->change(); + }); + + Schema::table('bill_items', function ($table) { + $table->decimal('quantity', 7, 2)->change(); + }); + } + } } diff --git a/database/migrations/2018_04_30_000000_change_quantity_column_invoice_bill_items.php b/database/migrations/2018_04_30_000000_change_quantity_column_invoice_bill_items.php deleted file mode 100644 index 1580e564e..000000000 --- a/database/migrations/2018_04_30_000000_change_quantity_column_invoice_bill_items.php +++ /dev/null @@ -1,38 +0,0 @@ -double('quantity', 7, 2)->change(); - }); - - Schema::table('bill_items', function ($table) { - $table->double('quantity', 7, 2)->change(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('invoice_items', function ($table) { - $table->integer('quantity')->change(); - }); - - Schema::table('bill_items', function ($table) { - $table->integer('quantity')->change(); - }); - } -}