1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Migrations\Migration; |
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
5
|
|
|
|
6
|
|
|
class TeamworkSetupTables extends Migration |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Run the migrations. |
10
|
|
|
* |
11
|
|
|
* @return void |
12
|
|
|
*/ |
13
|
|
|
public function up() |
14
|
|
|
{ |
15
|
|
|
Schema::table(\Config::get('teamwork.users_table'), function (Blueprint $table) { |
16
|
|
|
$table->integer('current_team_id')->unsigned()->nullable(); |
17
|
|
|
}); |
18
|
|
|
|
19
|
|
|
Schema::create(\Config::get('teamwork.teams_table'), function (Blueprint $table) { |
20
|
|
|
$table->increments('id')->unsigned(); |
21
|
|
|
$table->integer('owner_id')->unsigned()->nullable(); |
22
|
|
|
$table->string('name'); |
23
|
|
|
$table->timestamps(); |
24
|
|
|
}); |
25
|
|
|
|
26
|
|
|
Schema::create(\Config::get('teamwork.team_user_table'), function (Blueprint $table) { |
27
|
|
|
$table->bigInteger('user_id')->unsigned(); |
28
|
|
|
$table->integer('team_id')->unsigned(); |
29
|
|
|
$table->timestamps(); |
30
|
|
|
|
31
|
|
|
$table->foreign('user_id') |
32
|
|
|
->references(\Config::get('teamwork.user_foreign_key')) |
33
|
|
|
->on(\Config::get('teamwork.users_table')) |
34
|
|
|
->onUpdate('cascade') |
35
|
|
|
->onDelete('cascade'); |
36
|
|
|
|
37
|
|
|
$table->foreign('team_id') |
38
|
|
|
->references('id') |
39
|
|
|
->on(\Config::get('teamwork.teams_table')) |
40
|
|
|
->onDelete('cascade'); |
41
|
|
|
}); |
42
|
|
|
|
43
|
|
|
Schema::create(\Config::get('teamwork.team_invites_table'), function (Blueprint $table) { |
44
|
|
|
$table->increments('id'); |
45
|
|
|
$table->bigInteger('user_id')->unsigned(); |
46
|
|
|
$table->integer('team_id')->unsigned(); |
47
|
|
|
$table->enum('type', ['invite', 'request']); |
48
|
|
|
$table->string('email'); |
49
|
|
|
$table->string('accept_token'); |
50
|
|
|
$table->string('deny_token'); |
51
|
|
|
$table->timestamps(); |
52
|
|
|
$table->foreign('team_id') |
53
|
|
|
->references('id') |
54
|
|
|
->on(\Config::get('teamwork.teams_table')) |
55
|
|
|
->onDelete('cascade'); |
56
|
|
|
}); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Reverse the migrations. |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function down() |
65
|
|
|
{ |
66
|
|
|
Schema::table(\Config::get('teamwork.users_table'), function (Blueprint $table) { |
67
|
|
|
$table->dropColumn('current_team_id'); |
68
|
|
|
}); |
69
|
|
|
|
70
|
|
|
Schema::table(\Config::get('teamwork.team_user_table'), function (Blueprint $table) { |
71
|
|
|
if (DB::getDriverName() !== 'sqlite') { |
72
|
|
|
$table->dropForeign(\Config::get('teamwork.team_user_table').'_user_id_foreign'); |
73
|
|
|
} |
74
|
|
|
if (DB::getDriverName() !== 'sqlite') { |
75
|
|
|
$table->dropForeign(\Config::get('teamwork.team_user_table').'_team_id_foreign'); |
76
|
|
|
} |
77
|
|
|
}); |
78
|
|
|
|
79
|
|
|
Schema::drop(\Config::get('teamwork.team_user_table')); |
80
|
|
|
Schema::drop(\Config::get('teamwork.team_invites_table')); |
81
|
|
|
Schema::drop(\Config::get('teamwork.teams_table')); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|