|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Database\Migrations\Migration; |
|
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
5
|
|
|
use Xoco70\LaravelTournaments\DBHelpers; |
|
6
|
|
|
|
|
7
|
|
|
class CreateLtCategoryTable extends Migration |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Run the migrations. |
|
11
|
|
|
* |
|
12
|
|
|
* @return void |
|
13
|
|
|
*/ |
|
14
|
|
|
public function up() |
|
15
|
|
|
{ |
|
16
|
|
|
Schema::create('category', function (Blueprint $table) { |
|
17
|
|
|
$table->increments('id'); |
|
18
|
|
|
$table->string('name'); |
|
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->unique(['name', 'gender', 'isTeam', 'ageCategory', 'ageMin', 'ageMax', 'gradeCategory', 'gradeMin', 'gradeMax'], 'category_fields_unique'); |
|
28
|
|
|
$table->timestamps(); |
|
29
|
|
|
$table->engine = 'InnoDB'; |
|
30
|
|
|
}); |
|
31
|
|
|
|
|
32
|
|
|
Schema::create('championship', function (Blueprint $table) { |
|
33
|
|
|
$table->increments('id'); |
|
34
|
|
|
$table->integer('tournament_id')->unsigned()->index(); |
|
35
|
|
|
$table->integer('category_id')->unsigned()->index(); |
|
36
|
|
|
$table->unique(['tournament_id', 'category_id']); |
|
37
|
|
|
|
|
38
|
|
|
$table->foreign('tournament_id') |
|
39
|
|
|
->references('id') |
|
40
|
|
|
->on('tournament') |
|
41
|
|
|
->onUpdate('cascade') |
|
42
|
|
|
->onDelete('cascade'); |
|
43
|
|
|
|
|
44
|
|
|
$table->foreign('category_id') |
|
45
|
|
|
->references('id') |
|
46
|
|
|
->on('category') |
|
47
|
|
|
->onDelete('cascade'); |
|
48
|
|
|
|
|
49
|
|
|
$table->timestamps(); |
|
50
|
|
|
$table->softDeletes(); |
|
51
|
|
|
$table->engine = 'InnoDB'; |
|
52
|
|
|
}); |
|
53
|
|
|
|
|
54
|
|
|
Schema::create('competitor', function (Blueprint $table) { |
|
55
|
|
|
$table->increments('id'); |
|
56
|
|
|
$table->integer('short_id')->unsigned()->nullable(); |
|
57
|
|
|
$table->integer('championship_id')->unsigned()->index(); |
|
58
|
|
|
$table->foreign('championship_id') |
|
59
|
|
|
->references('id') |
|
60
|
|
|
->on('championship') |
|
61
|
|
|
->onUpdate('cascade') |
|
62
|
|
|
->onDelete('cascade'); |
|
63
|
|
|
|
|
64
|
|
|
$table->integer('user_id')->unsigned()->index(); |
|
65
|
|
|
$table->foreign('user_id') |
|
66
|
|
|
->references('id') |
|
67
|
|
|
->on('users') |
|
68
|
|
|
->onUpdate('cascade') |
|
69
|
|
|
->onDelete('cascade'); |
|
70
|
|
|
|
|
71
|
|
|
$table->unique(['championship_id', 'short_id']); |
|
72
|
|
|
$table->unique(['championship_id', 'user_id']); |
|
73
|
|
|
|
|
74
|
|
|
$table->boolean('confirmed'); |
|
75
|
|
|
|
|
76
|
|
|
$table->timestamps(); |
|
77
|
|
|
$table->softDeletes(); |
|
78
|
|
|
$table->engine = 'InnoDB'; |
|
79
|
|
|
}); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Reverse the migrations. |
|
84
|
|
|
* |
|
85
|
|
|
* @return void |
|
86
|
|
|
*/ |
|
87
|
|
|
public function down() |
|
88
|
|
|
{ |
|
89
|
|
|
DBHelpers::setFKCheckOff(); |
|
90
|
|
|
Schema::dropIfExists('competitor'); |
|
91
|
|
|
Schema::dropIfExists('championship'); |
|
92
|
|
|
Schema::dropIfExists('category'); |
|
93
|
|
|
DBHelpers::setFKCheckOn(); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|