Passed
Push — master ( c0f464...9c6e80 )
by Gabriel
11:21
created

CreateTransactionsTable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 24
c 1
b 0
f 1
dl 0
loc 45
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A change() 0 32 2
1
<?php
2
3
declare(strict_types=1);
4
5
use Phinx\Migration\AbstractMigration;
6
7
/**
8
 * Class CreateTransactionsTable
9
 */
10
final class CreateTransactionsTable extends AbstractMigration
11
{
12
    /**
13
     * Change Method.
14
     *
15
     * Write your reversible migrations using this method.
16
     *
17
     * More information on writing migrations is available here:
18
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
19
     *
20
     * Remember to call "create()" or "update()" and NOT "save()" when working
21
     * with the Table class.
22
     */
23
    public function change(): void
24
    {
25
        $table_name = \ByTIC\Payments\Utility\PaymentsModels::transactions()->getTable();
26
        $exists = $this->hasTable($table_name);
27
        if ($exists) {
28
            return;
29
        }
30
31
        $table = $this->table($table_name)
32
            ->addColumn('id_purchase', 'biginteger')
33
            ->addColumn('gateway', 'string')
34
            ->addColumn('currency', 'string', ['limit' => '3'])
35
36
            ->addColumn('card', 'string')
37
            ->addColumn('code', 'string')
38
            ->addColumn('reference', 'string')
39
            ->addColumn('metadata', 'json')
40
            ->addColumn('modified', 'timestamp', [
41
                'default' => 'CURRENT_TIMESTAMP',
42
                'update' => 'CURRENT_TIMESTAMP',
43
            ])
44
            ->addColumn('created', 'timestamp', [
45
                'default' => 'CURRENT_TIMESTAMP',
46
            ]);
47
48
        $table->addIndex(['id_purchase']);
49
        $table->addIndex(['currency']);
50
        $table->addIndex(['card']);
51
        $table->addIndex(['code']);
52
        $table->addIndex(['reference']);
53
54
        $table->save();
55
    }
56
}
57