Skip to content

Commit

Permalink
Update 2017_04_05_103357_alter_id_in_transactions_table.php
Browse files Browse the repository at this point in the history
  • Loading branch information
hpakdaman authored Apr 5, 2017
1 parent 06424ac commit 5faf740
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions migrations/2017_04_05_103357_alter_id_in_transactions_table.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
Expand All @@ -12,15 +13,25 @@ function getTable()
return config('gateway.table', 'gateway_transactions');
}

function getLogTable()
{
return $this->getTable().'_logs';
}


/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\Illuminate\Support\Facades\DB::statement("update `" . $this->getTable() . "` set `payment_date`=null WHERE `payment_date`=0;");
\Illuminate\Support\Facades\DB::statement("ALTER TABLE `" . $this->getTable() . "` CHANGE `id` `id` BIGINT UNSIGNED NOT NULL;");
DB::statement("ALTER TABLE `" . $this->getLogTable() . "` drop foreign key transactions_logs_transaction_id_foreign;");
DB::statement("ALTER TABLE `" . $this->getLogTable() . "` DROP INDEX transactions_logs_transaction_id_foreign;");
DB::statement("update `" . $this->getTable() . "` set `payment_date`=null WHERE `payment_date`=0;");
DB::statement("ALTER TABLE `" . $this->getTable() . "` CHANGE `id` `id` BIGINT UNSIGNED NOT NULL;");
DB::statement("ALTER TABLE `" . $this->getLogTable() . "` CHANGE `transaction_id` `transaction_id` BIGINT UNSIGNED NOT NULL;");
DB::statement("ALTER TABLE `" . $this->getLogTable() . "` ADD INDEX `transactions_logs_transaction_id_foreign` (`transaction_id`);");
}

/**
Expand All @@ -30,6 +41,6 @@ public function up()
*/
public function down()
{
\Illuminate\Support\Facades\DB::statement("ALTER TABLE `" . $this->getTable() . "` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL;");
DB::statement("ALTER TABLE `" . $this->getTable() . "` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL;");
}
}

0 comments on commit 5faf740

Please sign in to comment.