From 68073afcac7ed36a84c8b22c1f4a9752f407da61 Mon Sep 17 00:00:00 2001 From: tmusonza Date: Sun, 7 Jul 2019 22:57:19 -0400 Subject: [PATCH] User bigIncrements for Laravel 5.8 and above --- database/migrations/create_groups_tables.php | 361 +++++++++++++------ tests/GroupsTestCase.php | 1 + 2 files changed, 245 insertions(+), 117 deletions(-) diff --git a/database/migrations/create_groups_tables.php b/database/migrations/create_groups_tables.php index 2904e25..b55b5cd 100644 --- a/database/migrations/create_groups_tables.php +++ b/database/migrations/create_groups_tables.php @@ -6,6 +6,13 @@ class CreateGroupsTables extends Migration { + protected $useBigIncrements; + + public function __construct() + { + $this->useBigIncrements = app()::VERSION >= 5.8; + } + /** * Run the migrations. * @@ -13,123 +20,243 @@ class CreateGroupsTables extends Migration */ public function up() { - Schema::create('groups', function (Blueprint $table) { - $table->increments('id'); - $table->string('name'); - $table->string('description')->nullable(); - $table->string('short_description')->nullable(); - $table->string('image')->nullable(); - $table->string('url')->nullable(); - $table->integer('user_id')->unsigned(); - $table->boolean('private')->unsigned()->default(false); - $table->integer('conversation_id')->unsigned()->nullable(); - $table->text('extra_info')->nullable(); - $table->text('settings')->nullable(); - $table->timestamps(); - - $table->foreign('user_id') - ->references('id') - ->on('users') - ->onDelete('cascade'); - }); - - Schema::create('group_user', function (Blueprint $table) { - $table->increments('id'); - $table->integer('user_id')->unsigned(); - $table->integer('group_id')->unsigned(); - $table->timestamps(); - - $table->foreign('user_id') - ->references('id') - ->on('users') - ->onDelete('cascade'); - - $table->foreign('group_id') - ->references('id') - ->on('groups') - ->onDelete('cascade'); - }); - - Schema::create('posts', function (Blueprint $table) { - $table->increments('id'); - $table->string('title'); - $table->text('body'); - $table->string('type'); - $table->integer('user_id')->unsigned(); - $table->text('extra_info')->nullable(); - $table->timestamps(); - - $table->foreign('user_id') - ->references('id') - ->on('users') - ->onDelete('cascade'); - }); - - Schema::create('comments', function (Blueprint $table) { - $table->increments('id'); - $table->string('body'); - $table->integer('user_id')->unsigned(); - $table->integer('post_id')->unsigned(); - $table->string('type')->nullable(); - $table->timestamps(); - - $table->foreign('user_id') - ->references('id') - ->on('users'); - - $table->foreign('post_id') - ->references('id') - ->on('posts'); - }); - - Schema::create('group_post', function (Blueprint $table) { - $table->integer('group_id')->unsigned(); - $table->integer('post_id')->unsigned(); - $table->timestamps(); - - $table->foreign('group_id') - ->references('id') - ->on('groups') - ->onDelete('cascade'); - - $table->foreign('post_id') - ->references('id') - ->on('posts') - ->onDelete('cascade'); - }); - - Schema::create('likes', function (Blueprint $table) { - $table->integer('user_id')->index(); - $table->integer('likeable_id')->unsigned(); - $table->string('likeable_type'); - $table->primary(['user_id', 'likeable_id', 'likeable_type']); - $table->timestamps(); - }); - - Schema::create('reports', function (Blueprint $table) { - $table->integer('user_id')->index(); - $table->integer('reportable_id')->unsigned(); - $table->string('reportable_type'); - $table->primary(['user_id', 'reportable_id', 'reportable_type']); - $table->timestamps(); - }); - - Schema::create('group_request', function (Blueprint $table) { - $table->increments('id'); - $table->integer('user_id')->unsigned()->index(); - $table->integer('group_id')->unsigned()->index(); - $table->timestamps(); - - $table->foreign('group_id') - ->references('id') - ->on('groups') - ->onDelete('cascade'); - - $table->foreign('user_id') - ->references('id') - ->on('users') - ->onDelete('cascade'); - }); + if ($this->useBigIncrements) { + Schema::create('groups', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->string('name'); + $table->string('description')->nullable(); + $table->string('short_description')->nullable(); + $table->string('image')->nullable(); + $table->string('url')->nullable(); + $table->integer('user_id')->unsignedBigIntegers(); + $table->boolean('private')->unsigned()->default(false); + $table->integer('conversation_id')->unsignedBigIntegers()->nullable(); + $table->text('extra_info')->nullable(); + $table->text('settings')->nullable(); + $table->timestamps(); + + $table->foreign('user_id') + ->references('id') + ->on('users') + ->onDelete('cascade'); + }); + + Schema::create('group_user', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->integer('user_id')->unsignedBigIntegers(); + $table->integer('group_id')->unsignedBigIntegers(); + $table->timestamps(); + + $table->foreign('user_id') + ->references('id') + ->on('users') + ->onDelete('cascade'); + + $table->foreign('group_id') + ->references('id') + ->on('groups') + ->onDelete('cascade'); + }); + + Schema::create('posts', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->string('title'); + $table->text('body'); + $table->string('type'); + $table->integer('user_id')->unsignedBigIntegers(); + $table->text('extra_info')->nullable(); + $table->timestamps(); + + $table->foreign('user_id') + ->references('id') + ->on('users') + ->onDelete('cascade'); + }); + + Schema::create('comments', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->string('body'); + $table->integer('user_id')->unsignedBigIntegers(); + $table->integer('post_id')->unsignedBigIntegers(); + $table->string('type')->nullable(); + $table->timestamps(); + + $table->foreign('user_id') + ->references('id') + ->on('users'); + + $table->foreign('post_id') + ->references('id') + ->on('posts'); + }); + + Schema::create('group_post', function (Blueprint $table) { + $table->integer('group_id')->unsignedBigIntegers(); + $table->integer('post_id')->unsignedBigIntegers(); + $table->timestamps(); + + $table->foreign('group_id') + ->references('id') + ->on('groups') + ->onDelete('cascade'); + + $table->foreign('post_id') + ->references('id') + ->on('posts') + ->onDelete('cascade'); + }); + + Schema::create('likes', function (Blueprint $table) { + $table->integer('user_id')->index(); + $table->integer('likeable_id')->unsignedBigIntegers(); + $table->string('likeable_type'); + $table->primary(['user_id', 'likeable_id', 'likeable_type']); + $table->timestamps(); + }); + + Schema::create('reports', function (Blueprint $table) { + $table->integer('user_id')->index(); + $table->integer('reportable_id')->unsignedBigIntegers(); + $table->string('reportable_type'); + $table->primary(['user_id', 'reportable_id', 'reportable_type']); + $table->timestamps(); + }); + + Schema::create('group_request', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->integer('user_id')->unsignedBigIntegers()->index(); + $table->integer('group_id')->unsignedBigIntegers()->index(); + $table->timestamps(); + + $table->foreign('group_id') + ->references('id') + ->on('groups') + ->onDelete('cascade'); + + $table->foreign('user_id') + ->references('id') + ->on('users') + ->onDelete('cascade'); + }); + } else { + Schema::create('groups', function (Blueprint $table) { + $table->increments('id'); + $table->string('name'); + $table->string('description')->nullable(); + $table->string('short_description')->nullable(); + $table->string('image')->nullable(); + $table->string('url')->nullable(); + $table->integer('user_id')->unsigned(); + $table->boolean('private')->unsigned()->default(false); + $table->integer('conversation_id')->unsigned()->nullable(); + $table->text('extra_info')->nullable(); + $table->text('settings')->nullable(); + $table->timestamps(); + + $table->foreign('user_id') + ->references('id') + ->on('users') + ->onDelete('cascade'); + }); + + Schema::create('group_user', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned(); + $table->integer('group_id')->unsigned(); + $table->timestamps(); + + $table->foreign('user_id') + ->references('id') + ->on('users') + ->onDelete('cascade'); + + $table->foreign('group_id') + ->references('id') + ->on('groups') + ->onDelete('cascade'); + }); + + Schema::create('posts', function (Blueprint $table) { + $table->increments('id'); + $table->string('title'); + $table->text('body'); + $table->string('type'); + $table->integer('user_id')->unsigned(); + $table->text('extra_info')->nullable(); + $table->timestamps(); + + $table->foreign('user_id') + ->references('id') + ->on('users') + ->onDelete('cascade'); + }); + + Schema::create('comments', function (Blueprint $table) { + $table->increments('id'); + $table->string('body'); + $table->integer('user_id')->unsigned(); + $table->integer('post_id')->unsigned(); + $table->string('type')->nullable(); + $table->timestamps(); + + $table->foreign('user_id') + ->references('id') + ->on('users'); + + $table->foreign('post_id') + ->references('id') + ->on('posts'); + }); + + Schema::create('group_post', function (Blueprint $table) { + $table->integer('group_id')->unsigned(); + $table->integer('post_id')->unsigned(); + $table->timestamps(); + + $table->foreign('group_id') + ->references('id') + ->on('groups') + ->onDelete('cascade'); + + $table->foreign('post_id') + ->references('id') + ->on('posts') + ->onDelete('cascade'); + }); + + Schema::create('likes', function (Blueprint $table) { + $table->integer('user_id')->index(); + $table->integer('likeable_id')->unsigned(); + $table->string('likeable_type'); + $table->primary(['user_id', 'likeable_id', 'likeable_type']); + $table->timestamps(); + }); + + Schema::create('reports', function (Blueprint $table) { + $table->integer('user_id')->index(); + $table->integer('reportable_id')->unsigned(); + $table->string('reportable_type'); + $table->primary(['user_id', 'reportable_id', 'reportable_type']); + $table->timestamps(); + }); + + Schema::create('group_request', function (Blueprint $table) { + $table->increments('id'); + $table->integer('user_id')->unsigned()->index(); + $table->integer('group_id')->unsigned()->index(); + $table->timestamps(); + + $table->foreign('group_id') + ->references('id') + ->on('groups') + ->onDelete('cascade'); + + $table->foreign('user_id') + ->references('id') + ->on('users') + ->onDelete('cascade'); + }); + } } /** diff --git a/tests/GroupsTestCase.php b/tests/GroupsTestCase.php index c3e9f48..b0a0c41 100644 --- a/tests/GroupsTestCase.php +++ b/tests/GroupsTestCase.php @@ -78,6 +78,7 @@ protected function getEnvironmentSetUp($app) ]); $app['config']->set('musonza_groups.user_model', User::class); + $app['config']->set('musonza_groups.big_increments', true); } protected function getPackageProviders($app)