CreateTaxonomies   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 90
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 0 68 1
A down() 0 8 1
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
6
class CreateTaxonomies extends Migration
7
{
8
    /**
9
     * Run the migrations.
10
     *
11
     * @return void
12
     */
13
    public function up()
14
    {
15
        Schema::create(
16
            'taxonomy_vocabularies',
17
            function (Blueprint $table) {
18
                $table->increments('id');
19
                $table->string('name', 255);
20
                $table->string('machine_name', 255)->unique();
21
                $table->text('description')->nullable();
22
                $table->integer('hierarchy')->default(0); // 0 = disabled, 1 = single, 2 = multiple
23
                $table->integer('translatable')->default(1);
24
            }
25
        );
26
27
        Schema::create(
28
            'taxonomy_terms',
29
            function (Blueprint $table) {
30
                $table->increments('id');
31
                $table->unsignedInteger('vocabulary_id');
32
                $table->integer('type')->default(0); // 0 = simple, 1 = category
33
34
                $table->foreign('vocabulary_id')->references('id')->on('taxonomy_vocabularies');
35
            }
36
        );
37
38
        Schema::create(
39
            'taxonomy_terms_data',
40
            function (Blueprint $table) {
41
                $table->increments('id');
42
                $table->unsignedInteger('term_id');
43
                $table->unsignedInteger('language_id');
44
                $table->string('title', 255);
45
                $table->text('description')->nullable();
46
47
                $table->foreign('term_id')->references('id')->on('taxonomy_terms');
48
                $table->foreign('language_id')->references('id')->on('languages');
49
            }
50
        );
51
52
        Schema::create(
53
            'taxonomy_term_hierarchy',
54
            function (Blueprint $table) {
55
                $table->unsignedInteger('term_id');
56
                $table->unsignedInteger('parent_id');
57
58
                $table->foreign('term_id')->references('id')->on('taxonomy_terms');
59
                $table->foreign('parent_id')->references('id')->on('taxonomy_terms');
60
61
                $table->primary(['term_id', 'parent_id']);
62
            }
63
        );
64
65
        Schema::create(
66
            'taxonomy_content',
67
            function (Blueprint $table) {
68
                $table->unsignedInteger('term_id');
69
                $table->unsignedInteger('relationable_id');
70
                $table->string('relationable_type');
71
72
                $table->foreign('term_id')->references('id')->on('taxonomy_terms');
73
74
                $table->primary(
75
                    ['term_id', 'relationable_id', 'relationable_type'],
76
                    'taxonomy_contents_composed_primary'
77
                );
78
            }
79
        );
80
    }
81
82
    /**
83
     * Reverse the migrations.
84
     *
85
     * @return void
86
     */
87
    public function down()
88
    {
89
        Schema::drop('taxonomy_content');
90
        Schema::drop('taxonomy_term_hierarchy');
91
        Schema::drop('taxonomy_terms_data');
92
        Schema::drop('taxonomy_terms');
93
        Schema::drop('taxonomy_vocabularies');
94
    }
95
}
96