diff --git a/config/teamwork.php b/config/teamwork.php new file mode 100644 index 0000000..58656d1 --- /dev/null +++ b/config/teamwork.php @@ -0,0 +1,84 @@ + config('auth.providers.users.model', App\User::class), + + /* + |-------------------------------------------------------------------------- + | Teamwork users Table + |-------------------------------------------------------------------------- + | + | This is the users table name used by Teamwork. + | + */ + 'users_table' => 'users', + + /* + |-------------------------------------------------------------------------- + | Teamwork Team Model + |-------------------------------------------------------------------------- + | + | This is the Team model used by Teamwork to create correct relations. Update + | the team if it is in a different namespace. + | + */ + 'team_model' => Mpociot\Teamwork\TeamworkTeam::class, + + /* + |-------------------------------------------------------------------------- + | Teamwork teams Table + |-------------------------------------------------------------------------- + | + | This is the teams table name used by Teamwork to save teams to the database. + | + */ + 'teams_table' => 'teams', + + /* + |-------------------------------------------------------------------------- + | Teamwork team_user Table + |-------------------------------------------------------------------------- + | + | This is the team_user table used by Teamwork to save assigned teams to the + | database. + | + */ + 'team_user_table' => 'team_user', + + /* + |-------------------------------------------------------------------------- + | User Foreign key on Teamwork's team_user Table (Pivot) + |-------------------------------------------------------------------------- + */ + 'user_foreign_key' => 'id', + + /* + |-------------------------------------------------------------------------- + | Teamwork Team Invite Model + |-------------------------------------------------------------------------- + | + | This is the Team Invite model used by Teamwork to create correct relations. + | Update the team if it is in a different namespace. + | + */ + 'invite_model' => Mpociot\Teamwork\TeamInvite::class, + + /* + |-------------------------------------------------------------------------- + | Teamwork team invites Table + |-------------------------------------------------------------------------- + | + | This is the team invites table name used by Teamwork to save sent/pending + | invitation into teams to the database. + | + */ + 'team_invites_table' => 'team_invites', +]; diff --git a/database/migrations/2020_09_10_174112_teamwork_setup_tables.php b/database/migrations/2020_09_10_174112_teamwork_setup_tables.php new file mode 100644 index 0000000..144f40c --- /dev/null +++ b/database/migrations/2020_09_10_174112_teamwork_setup_tables.php @@ -0,0 +1,83 @@ +integer('current_team_id')->unsigned()->nullable(); + }); + + Schema::create(\Config::get('teamwork.teams_table'), function (Blueprint $table) { + $table->increments('id')->unsigned(); + $table->integer('owner_id')->unsigned()->nullable(); + $table->string('name'); + $table->timestamps(); + }); + + Schema::create(\Config::get('teamwork.team_user_table'), function (Blueprint $table) { + $table->bigInteger('user_id')->unsigned(); + $table->integer('team_id')->unsigned(); + $table->timestamps(); + + $table->foreign('user_id') + ->references(\Config::get('teamwork.user_foreign_key')) + ->on(\Config::get('teamwork.users_table')) + ->onUpdate('cascade') + ->onDelete('cascade'); + + $table->foreign('team_id') + ->references('id') + ->on(\Config::get('teamwork.teams_table')) + ->onDelete('cascade'); + }); + + Schema::create(\Config::get('teamwork.team_invites_table'), function (Blueprint $table) { + $table->increments('id'); + $table->bigInteger('user_id')->unsigned(); + $table->integer('team_id')->unsigned(); + $table->enum('type', ['invite', 'request']); + $table->string('email'); + $table->string('accept_token'); + $table->string('deny_token'); + $table->timestamps(); + $table->foreign('team_id') + ->references('id') + ->on(\Config::get('teamwork.teams_table')) + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table(\Config::get('teamwork.users_table'), function (Blueprint $table) { + $table->dropColumn('current_team_id'); + }); + + Schema::table(\Config::get('teamwork.team_user_table'), function (Blueprint $table) { + if (DB::getDriverName() !== 'sqlite') { + $table->dropForeign(\Config::get('teamwork.team_user_table').'_user_id_foreign'); + } + if (DB::getDriverName() !== 'sqlite') { + $table->dropForeign(\Config::get('teamwork.team_user_table').'_team_id_foreign'); + } + }); + + Schema::drop(\Config::get('teamwork.team_user_table')); + Schema::drop(\Config::get('teamwork.team_invites_table')); + Schema::drop(\Config::get('teamwork.teams_table')); + } +}