forked from larabook/gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2017_04_05_103357_alter_id_in_transactions_table.php
62 lines (49 loc) · 1.67 KB
/
2017_04_05_103357_alter_id_in_transactions_table.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AlterIdInTransactionsTable extends Migration
{
function getTable()
{
return config('gateway.table', 'gateway_transactions');
}
function getLogTable()
{
return $this->getTable().'_logs';
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
try {
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;");
} catch (Exception $e) {
}
try {
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`);");
} catch (Exception $e) {
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Don't check for foreign key constraints when executing below query in current session
DB::statement('set foreign_key_checks=0');
DB::statement("ALTER TABLE `" . $this->getTable() . "` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL;");
// Ok! now DBMS can check for foregin key constraints
DB::statement('set foreign_key_checks=1');
}
}