CreateUserSocialTable::down()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\DB;
6
7
class CreateUserSocialTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        Schema::create('user_socials', function (Blueprint $table) {
17
            $table->increments('id');
18
            $table->integer('user_id')->unsigned();
19
            $table->string('provider');
20
            $table->string('social_id')->index();
21
            $table->string('email')->index()->nullable();
22
            $table->string('avatar')->nullable();
23
            $table->string('token');
24
            $table->string('refresh_token')->nullable();
25
            $table->integer('expires_in')->nullable();
26
            $table->timestamps();
27
28
            $table->foreign('user_id')
29
                  ->references('id')
30
                  ->on('users')
31
                  ->onDelete('cascade');
32
        });
33
34
        DB::statement('ALTER TABLE `users` MODIFY `password` VARCHAR(64);');
35
    }
36
37
    /**
38
     * Reverse the migrations.
39
     *
40
     * @return void
41
     */
42
    public function down()
43
    {
44
        Schema::drop('user_socials');
45
46
        if (DB::table('users')->count() === 0) {
47
            DB::statement('ALTER TABLE `users` MODIFY `password` VARCHAR(64) NOT NULL;');
48
        }
49
    }
50
}
51