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

AddTwoFactorAuthColumnsToTwillUsers   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 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 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