Passed
Push — master ( c36ed8...8867a0 )
by Quentin
13:25 queued 05:48
created

AddTwoFactorAuthColumnsToTwillUsers::down()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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