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

CreateTokensTable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A change() 0 27 2
1
<?php
2
3
declare(strict_types=1);
4
5
use Phinx\Migration\AbstractMigration;
6
7
/**
8
 * Class CreateTokensTable
9
 */
10
final class CreateTokensTable 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::tokens()->getTable();
26
        $exists = $this->hasTable($table_name);
27
        if ($exists) {
28
            return;
29
        }
30
31
        $table = $this->table($table_name)
32
            ->addColumn('id_method', 'biginteger')
33
            ->addColumn('gateway', 'string')
34
            ->addColumn('token_id', 'string')
35
            ->addColumn('expiration', 'timestamp')
36
            ->addColumn('modified', 'timestamp', [
37
                'default' => 'CURRENT_TIMESTAMP',
38
                'update' => 'CURRENT_TIMESTAMP',
39
            ])
40
            ->addColumn('created', 'timestamp', [
41
                'default' => 'CURRENT_TIMESTAMP',
42
            ]);
43
44
        $table->addIndex(['id_method']);
45
        $table->addIndex(['gateway']);
46
        $table->addIndex(['token_id']);
47
        $table->addIndex(['id_method', 'token_id'], ['unique' => true]);
48
49
        $table->save();
50
    }
51
}
52