Completed
Push — master ( dc40d0...a009a1 )
by Marcel
05:50
created

TeamworkSetupTables::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
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