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