1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Schema; |
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
5
|
|
|
use Illuminate\Database\Migrations\Migration; |
6
|
|
|
|
7
|
|
|
class CreateTaxonomyTables extends Migration |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Run the migrations. |
11
|
|
|
* |
12
|
|
|
* @return void |
13
|
|
|
*/ |
14
|
|
|
public function up() |
15
|
|
|
{ |
16
|
|
|
$this->createVocabulariesTable(); |
17
|
|
|
|
18
|
|
|
$this->createTermsTable(); |
19
|
|
|
|
20
|
|
|
$this->createVocabulariablesTable(); |
21
|
|
|
|
22
|
|
|
$this->createTermablesTable(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Taxonomy vocabularies table |
27
|
|
|
*/ |
28
|
|
|
public function createVocabulariesTable() |
29
|
|
|
{ |
30
|
|
|
Schema::create('vocabularies', function (Blueprint $table) { |
31
|
|
|
$table->increments('id'); |
32
|
|
|
$table->string('system_name')->unique(); |
33
|
|
|
$table->string('name'); |
34
|
|
|
$table->text('description')->nullable(); |
35
|
|
|
$table->unsignedBigInteger('has_hierarchy')->default(1); |
36
|
|
|
}); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Taxonomy terms table |
41
|
|
|
*/ |
42
|
|
|
public function createTermsTable() |
43
|
|
|
{ |
44
|
|
|
Schema::create('terms', function (Blueprint $table) { |
45
|
|
|
$table->increments('id'); |
46
|
|
|
$table->string('name'); |
47
|
|
|
$table->string('system_name')->nullable()->unique(); |
48
|
|
|
// $table->string('slug')->nullable()->unique(); |
49
|
|
|
$table->text('description')->nullable(); |
50
|
|
|
|
51
|
|
|
// Nested https://github.com/lazychaser/laravel-nestedset |
52
|
|
|
$table->unsignedInteger('_lft')->default(0); |
53
|
|
|
$table->unsignedInteger('_rgt')->default(0); |
54
|
|
|
$table->unsignedInteger('parent_id')->nullable(); |
55
|
|
|
|
56
|
|
|
$table->integer('weight')->default(0); |
57
|
|
|
$table->string('vocabulary'); |
58
|
|
|
// $table->json('options')->nullable(); |
59
|
|
|
$table->timestamps(); |
60
|
|
|
}); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Таблица сущностей "привязанных" к словарям |
65
|
|
|
*/ |
66
|
|
|
public function createVocabulariablesTable() |
67
|
|
|
{ |
68
|
|
|
Schema::create('vocabularyables', function (Blueprint $table) { |
69
|
|
|
$table->unsignedInteger('vocabulary_id'); |
70
|
|
|
$table->morphs('vocabularyable'); |
71
|
|
|
|
72
|
|
|
$table->foreign('vocabulary_id') |
73
|
|
|
->references('id') |
74
|
|
|
->on('vocabularies') |
75
|
|
|
->onDelete('CASCADE'); |
76
|
|
|
}); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Таблица сущностей "привязанных" к термам |
81
|
|
|
*/ |
82
|
|
|
public function createTermablesTable() |
83
|
|
|
{ |
84
|
|
|
Schema::create('termables', function (Blueprint $table) { |
85
|
|
|
$table->unsignedInteger('term_id'); |
86
|
|
|
$table->morphs('termable'); |
87
|
|
|
|
88
|
|
|
$table->foreign('term_id') |
89
|
|
|
->references('id') |
90
|
|
|
->on('terms') |
91
|
|
|
->onDelete('CASCADE'); |
92
|
|
|
}); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Reverse the migrations. |
97
|
|
|
* |
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
|
|
public function down() |
101
|
|
|
{ |
102
|
|
|
Schema::dropIfExists('termables'); |
103
|
|
|
Schema::dropIfExists('vocabularyables'); |
104
|
|
|
Schema::dropIfExists('terms'); |
105
|
|
|
Schema::dropIfExists('vocabularies'); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|