AddApiTokensTable20210823152146::up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 17
c 3
b 0
f 0
nc 1
nop 0
dl 0
loc 26
rs 9.7
1
<?php
2
3
namespace Platine\Framework\Migration;
4
5
use Platine\Database\Schema\CreateTable;
6
use Platine\Framework\Migration\AbstractMigration;
7
8
class AddApiTokensTable20210823152146 extends AbstractMigration
9
{
10
    public function up(): void
11
    {
12
      //Action when migrate up
13
        $this->create('tokens', function (CreateTable $table) {
14
            $table->integer('id')
15
                    ->autoincrement()
16
                    ->primary();
17
18
            $table->string('refresh_token')
19
                   ->unique()
20
                   ->notNull();
21
22
            $table->datetime('expire_at')
23
                  ->notNull();
24
25
            $table->integer('user_id')
26
                   ->description('The owner of the token')
27
                   ->notNull();
28
29
            $table->timestamps();
30
            
31
            $table->foreign('user_id')
32
                    ->references('users', 'id')
33
                    ->onDelete('NO ACTION');
34
            
35
            $table->engine('INNODB');
36
        });
37
    }
38
39
    public function down(): void
40
    {
41
      //Action when migrate down
42
        $this->drop('tokens');
43
    }
44
}
45