AddActiveTokenFieldToUsersTable::down()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 3
eloc 6
c 2
b 1
f 0
nc 4
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
class AddActiveTokenFieldToUsersTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        if (!Schema::hasColumn('users', 'token')) {
17
            Schema::table('users', function (Blueprint $table) {
18
                $table->string('token', 24)->unique()->after('remember_token');
19
            });
20
        }
21
22
        if (!Schema::hasColumn('users', 'active')) {
23
            Schema::table('users', function (Blueprint $table) {
24
                $table->tinyInteger('active')->default(0)->after('token');
25
            });
26
        }
27
    }
28
29
    /**
30
     * Reverse the migrations.
31
     *
32
     * @return void
33
     */
34
    public function down()
35
    {
36
        if (Schema::hasColumn('users', 'token')) {
37
            Schema::table('users', function (Blueprint $table) {
38
                $table->dropColumn('token');
39
            });
40
        }
41
42
        if (Schema::hasColumn('users', 'active')) {
43
            Schema::table('users', function (Blueprint $table) {
44
                $table->dropColumn('active');
45
            });
46
        }
47
    }
48
}
49