1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Migrations\Migration; |
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
5
|
|
|
|
6
|
|
|
class CreateCategoryTable extends Migration |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Run the migrations. |
10
|
|
|
* |
11
|
|
|
* @return void |
12
|
|
|
*/ |
13
|
|
|
public function up() |
14
|
|
|
{ |
15
|
|
|
Schema::create('category', function (Blueprint $table) { |
16
|
|
|
$table->increments('id'); |
17
|
|
|
$table->string('name'); |
18
|
|
|
$table->string('alias')->default(''); |
19
|
|
|
$table->string('gender')->nullable(); |
20
|
|
|
$table->integer('isTeam')->unsigned()->default(0); |
21
|
|
|
$table->integer('ageCategory')->unsigned()->default(0); // 0 = none, 1 = child, 2= teenager, 3 = adult, 4 = master |
22
|
|
|
$table->integer('ageMin')->unsigned()->default(0); |
23
|
|
|
$table->integer('ageMax')->unsigned()->default(0); |
24
|
|
|
$table->integer('gradeCategory')->unsigned()->default(0); |
25
|
|
|
$table->integer('gradeMin')->unsigned()->default(0); |
26
|
|
|
$table->integer('gradeMax')->unsigned()->default(0); |
27
|
|
|
// $table->foreign('gradeMin') |
|
|
|
|
28
|
|
|
// ->references('id') |
29
|
|
|
// ->on('grade'); |
30
|
|
|
// $table->foreign('gradeMax') |
31
|
|
|
// ->references('id') |
32
|
|
|
// ->on('grade'); |
33
|
|
|
$table->unique(['name', 'alias', 'gender', 'isTeam', 'ageCategory', 'ageMin', 'ageMax', 'gradeCategory', 'gradeMin', 'gradeMax'], 'category_fields_unique'); |
34
|
|
|
$table->timestamps(); |
35
|
|
|
$table->engine = 'InnoDB'; |
36
|
|
|
}); |
37
|
|
|
|
38
|
|
|
Schema::create('championship', function (Blueprint $table) { |
39
|
|
|
$table->increments('id'); |
40
|
|
|
$table->integer('tournament_id')->unsigned()->index(); |
41
|
|
|
$table->integer('category_id')->unsigned()->index(); |
42
|
|
|
$table->unique(['tournament_id', 'category_id']); |
43
|
|
|
|
44
|
|
|
$table->foreign('tournament_id') |
45
|
|
|
->references('id') |
46
|
|
|
->on('tournament') |
47
|
|
|
->onUpdate('cascade') |
48
|
|
|
->onDelete('cascade'); |
49
|
|
|
|
50
|
|
|
$table->foreign('category_id') |
51
|
|
|
->references('id') |
52
|
|
|
->on('category') |
53
|
|
|
->onDelete('cascade'); |
54
|
|
|
|
55
|
|
|
$table->timestamps(); |
56
|
|
|
$table->softDeletes(); |
57
|
|
|
$table->engine = 'InnoDB'; |
58
|
|
|
}); |
59
|
|
|
|
60
|
|
|
Schema::create('competitor', function (Blueprint $table) { |
61
|
|
|
$table->increments('id'); |
62
|
|
|
$table->integer('championship_id')->unsigned()->index(); |
63
|
|
|
$table->foreign('championship_id') |
64
|
|
|
->references('id') |
65
|
|
|
->on('championship') |
66
|
|
|
->onUpdate('cascade') |
67
|
|
|
->onDelete('cascade'); |
68
|
|
|
|
69
|
|
|
$table->integer('user_id')->unsigned()->index(); |
70
|
|
|
$table->foreign('user_id') |
71
|
|
|
->references('id') |
72
|
|
|
->on('users') |
73
|
|
|
->onUpdate('cascade') |
74
|
|
|
->onDelete('cascade'); |
75
|
|
|
|
76
|
|
|
$table->unique(['championship_id', 'user_id']); |
77
|
|
|
|
78
|
|
|
$table->boolean('confirmed'); |
79
|
|
|
|
80
|
|
|
$table->timestamps(); |
81
|
|
|
$table->softDeletes(); |
82
|
|
|
$table->engine = 'InnoDB'; |
83
|
|
|
}); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Reverse the migrations. |
88
|
|
|
* |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
public function down() |
92
|
|
|
{ |
93
|
|
|
DB::statement('SET FOREIGN_KEY_CHECKS = 0'); |
94
|
|
|
Schema::dropIfExists('competitor'); |
95
|
|
|
Schema::dropIfExists('championship'); |
96
|
|
|
Schema::dropIfExists('category'); |
97
|
|
|
DB::statement('SET FOREIGN_KEY_CHECKS = 1'); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.