CreateIntegrationsTables::down()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
use Illuminate\Database\Migrations\Migration;
5
use Illuminate\Database\Schema\Blueprint;
6
7
class CreateIntegrationsTables extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
17
        if (!\Muleta\Modules\Features\Resources\FeatureHelper::hasActiveFeature(
18
            [
19
                'integrations',
20
                'services',
21
            ]
22
        )){
23
            \Log::debug('Migration Ignorada por causa de Feature');
24
            return ;
25
        }
26
27
        Schema::create(
28
            'integrations',
29 View Code Duplication
            function (Blueprint $table) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
                $table->engine = 'InnoDB';
31
                $table->bigIncrements('id')->unsigned();
32
                $table->string('name', 255)->nullable();
33
                $table->string('code');
34
                $table->integer('status')->default(1);
35
                $table->unique(['code']);
36
                $table->timestamps();
37
                $table->softDeletes();
38
            }
39
        );
40
        Schema::create(
41
            'services',
42
            function (Blueprint $table) {
43
                $table->engine = 'InnoDB';
44
                $table->bigIncrements('id')->unsigned();
45
                $table->string('name', 255)->nullable();
46
                $table->integer('status')->default(1);
47
                $table->bigInteger('integration_id')->unsigned();
48
                $table->timestamps();
49
                $table->softDeletes();
50
            }
51
        );
52
53
        /**
54
         * Account
55
         */
56
        Schema::create(
57
            'accounts',
58
            function (Blueprint $table) {
59
                $table->engine = 'InnoDB';
60
                $table->bigIncrements('id')->unsigned();
61
                $table->string('username', 255);
62
                $table->string('email')->nullable();
63
                $table->string('password')->nullable();
64
                $table->integer('status')->default(1);
65
                $table->string('customize_url')->nullable();
66
                $table->bigInteger('integration_id')->unsigned();
67
                $table->unique(['username', 'integration_id']);
68
                $table->timestamps();
69
                $table->softDeletes();
70
            }
71
        );
72
        Schema::table(
73
            'accounts',
74
            function (Blueprint $table) {
75
                $table->foreign('integration_id')->references('id')->on('integrations');
76
            }
77
        );
78
        
79
        /**
80
         * Accountables
81
         */
82
        Schema::create(
83
            'accountables',
84 View Code Duplication
            function (Blueprint $table) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
                $table->engine = 'InnoDB';
86
                $table->bigIncrements('id')->unsigned();
87
                $table->bigInteger('account_id')->unsigned(); //->nullable();
88
                $table->boolean('is_sincronizado')->default(false);
89
                $table->string('accountable_id');
90
                $table->string('accountable_type', 255);
91
                $table->timestamps();
92
                $table->softDeletes();
93
            }
94
        );
95
        Schema::table(
96
            'accountables',
97
            function (Blueprint $table) {
98
                $table->foreign('account_id')->references('id')->on('accounts');
99
            }
100
        );
101
        
102
        /**
103
         * Tokens
104
         */
105
        Schema::create(
106
            'tokens',
107 View Code Duplication
            function (Blueprint $table) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
                $table->bigIncrements('id');
109
                $table->string('token');
110
                $table->integer('status')->default(1);
111
                $table->string('obs')->nullable();
112
                $table->json('scopes')->nullable();
113
                $table->bigInteger('account_id')->unsigned();
114
                $table->unique(['token', 'account_id']);
115
                $table->timestamps();
116
            }
117
        );
118
        Schema::table(
119
            'tokens',
120
            function (Blueprint $table) {
121
                $table->foreign('account_id')->references('id')->on('accounts');
122
            }
123
        );
124
    }
125
126
    /**
127
     * Reverse the migrations.
128
     *
129
     * @return void
130
     */
131
    public function down()
132
    {
133
        Schema::dropIfExists('integrations');
134
        Schema::dropIfExists('accounts');
135
        Schema::dropIfExists('accountables');
136
        Schema::dropIfExists('tokens');
137
    }
138
}
139