AddApiTokensTable20210823152146::down()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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('token')
19
                   ->unique()
20
                   ->notNull();
21
22
            $table->string('refresh_token')
23
                   ->unique()
24
                   ->notNull();
25
26
            $table->datetime('expire_at')
27
                  ->notNull();
28
29
            $table->integer('user_id')
30
                   ->description('The owner of the token')
31
                   ->notNull();
32
33
            $table->timestamps();
34
            
35
            $table->foreign('user_id')
36
                    ->references('users', 'id')
37
                    ->onDelete('NO ACTION');
38
            
39
            $table->engine('INNODB');
40
        });
41
    }
42
43
    public function down(): void
44
    {
45
      //Action when migrate down
46
        $this->drop('tokens');
47
    }
48
}
49