diff --git a/CHANGELOG.md b/CHANGELOG.md index 598859f8a..7e8cf1928 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ You can find and compare releases at the [GitHub release page](https://github.co ## Unreleased +## v6.42.0 + +### Added + +- Add `@hasOneThrough` directive https://github.com/nuwave/lighthouse/pull/2585 + ## v6.41.1 ### Fixed diff --git a/docs/6/api-reference/directives.md b/docs/6/api-reference/directives.md index 44fde0196..424a35c19 100644 --- a/docs/6/api-reference/directives.md +++ b/docs/6/api-reference/directives.md @@ -1738,7 +1738,7 @@ type User { } ``` -If the name of the relationship on the Eloquent model is different than the field name, +If the name of the relationship on the Eloquent model differs from the field name, you can override it by setting `relation`. ```graphql @@ -1841,7 +1841,7 @@ type User { } ``` -If the name of the relationship on the Eloquent model is different than the field name, +If the name of the relationship on the Eloquent model differs from the field name, you can override it by setting `relation`. ```graphql @@ -1850,6 +1850,41 @@ type User { } ``` +## @hasOneThrough + +```graphql +""" +Corresponds to [the Eloquent relationship HasOneThrough](https://laravel.com/docs/eloquent-relationships#has-one-through). +""" +directive @hasOneThrough( + """ + Specify the relationship method name in the model class, + if it is named different from the field in the schema. + """ + relation: String + + """ + Apply scopes to the underlying query. + """ + scopes: [String!] +) on FIELD_DEFINITION +``` + +```graphql +type Mechanic { + carOwner: Owner! @hasOneThrough +} +``` + +If the name of the relationship on the Eloquent model differs from the field name, +you can override it by setting `relation`. + +```graphql +type Mechanic { + carOwner: Owner! @hasOneThrough(relation: "owner") +} +``` + ## @in ```graphql diff --git a/docs/6/eloquent/relationships.md b/docs/6/eloquent/relationships.md index e3551a496..c10f79f8a 100644 --- a/docs/6/eloquent/relationships.md +++ b/docs/6/eloquent/relationships.md @@ -109,6 +109,16 @@ type Role { } ``` +## Has One Through + +Use the [@hasOneThrough](../api-reference/directives.md#hasonethrough) directive to define a [has-one-through relationship](https://laravel.com/docs/eloquent-relationships#has-one-through). + +```graphql +type Mechanic { + carOwner: Owner! @hasOneThrough +} +``` + ## Has Many Through Use the [@hasManyThrough](../api-reference/directives.md#hasmanythrough) directive to define a [has-many-through relationship](https://laravel.com/docs/eloquent-relationships#has-many-through). diff --git a/docs/master/api-reference/directives.md b/docs/master/api-reference/directives.md index 44fde0196..424a35c19 100644 --- a/docs/master/api-reference/directives.md +++ b/docs/master/api-reference/directives.md @@ -1738,7 +1738,7 @@ type User { } ``` -If the name of the relationship on the Eloquent model is different than the field name, +If the name of the relationship on the Eloquent model differs from the field name, you can override it by setting `relation`. ```graphql @@ -1841,7 +1841,7 @@ type User { } ``` -If the name of the relationship on the Eloquent model is different than the field name, +If the name of the relationship on the Eloquent model differs from the field name, you can override it by setting `relation`. ```graphql @@ -1850,6 +1850,41 @@ type User { } ``` +## @hasOneThrough + +```graphql +""" +Corresponds to [the Eloquent relationship HasOneThrough](https://laravel.com/docs/eloquent-relationships#has-one-through). +""" +directive @hasOneThrough( + """ + Specify the relationship method name in the model class, + if it is named different from the field in the schema. + """ + relation: String + + """ + Apply scopes to the underlying query. + """ + scopes: [String!] +) on FIELD_DEFINITION +``` + +```graphql +type Mechanic { + carOwner: Owner! @hasOneThrough +} +``` + +If the name of the relationship on the Eloquent model differs from the field name, +you can override it by setting `relation`. + +```graphql +type Mechanic { + carOwner: Owner! @hasOneThrough(relation: "owner") +} +``` + ## @in ```graphql diff --git a/docs/master/eloquent/relationships.md b/docs/master/eloquent/relationships.md index e3551a496..c10f79f8a 100644 --- a/docs/master/eloquent/relationships.md +++ b/docs/master/eloquent/relationships.md @@ -109,6 +109,16 @@ type Role { } ``` +## Has One Through + +Use the [@hasOneThrough](../api-reference/directives.md#hasonethrough) directive to define a [has-one-through relationship](https://laravel.com/docs/eloquent-relationships#has-one-through). + +```graphql +type Mechanic { + carOwner: Owner! @hasOneThrough +} +``` + ## Has Many Through Use the [@hasManyThrough](../api-reference/directives.md#hasmanythrough) directive to define a [has-many-through relationship](https://laravel.com/docs/eloquent-relationships#has-many-through). diff --git a/src/Schema/Directives/HasOneThroughDirective.php b/src/Schema/Directives/HasOneThroughDirective.php new file mode 100644 index 000000000..0b2a87591 --- /dev/null +++ b/src/Schema/Directives/HasOneThroughDirective.php @@ -0,0 +1,27 @@ +schema = /** @lang GraphQL */ ' + type Query { + tasks: [Task!]! @all + } + + type Task { + id: ID! + postStatus: PostStatus @hasOneThrough + } + + type PostStatus { + id: ID! + status: String + } + '; + + $post = factory(Post::class)->create(); + assert($post instanceof Post); + + $postStatus = factory(PostStatus::class)->make(); + assert($postStatus instanceof PostStatus); + $postStatus->post()->associate($post); + $postStatus->save(); + + $this->graphQL(/** @lang GraphQL */ ' + { + tasks { + id + postStatus { + id + status + } + } + } + ')->assertExactJson([ + 'data' => [ + 'tasks' => [ + [ + 'id' => (string) $post->task->id, + 'postStatus' => [ + 'id' => (string) $postStatus->id, + 'status' => $postStatus->status, + ], + ], + ], + ], + ]); + } +} diff --git a/tests/Utils/Models/Post.php b/tests/Utils/Models/Post.php index c99efd362..c5311f742 100644 --- a/tests/Utils/Models/Post.php +++ b/tests/Utils/Models/Post.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Database\Eloquent\SoftDeletes; @@ -28,43 +29,53 @@ * @property int|null $user_id * @property int $task_id * @property int|null $parent_id - * @property-read \Tests\Utils\Models\User $user + * + * Relations * @property-read \Illuminate\Database\Eloquent\Collection<\Tests\Utils\Models\Activity> $activity - * @property-read \Illuminate\Database\Eloquent\Collection<\Tests\Utils\Models\Comment> $comments - * @property-read \Tests\Utils\Models\Task $task - * @property-read \Tests\Utils\Models\Post $parent + * @property-read \Illuminate\Database\Eloquent\Collection<\Tests\Utils\Models\Category> $categories * @property-read \Illuminate\Database\Eloquent\Collection<\Tests\Utils\Models\Post> $children - * @property-read \Illuminate\Database\Eloquent\Collection<\Tests\Utils\Models\Tag> $tags + * @property-read \Illuminate\Database\Eloquent\Collection<\Tests\Utils\Models\Comment> $comments * @property-read \Illuminate\Database\Eloquent\Collection<\Tests\Utils\Models\Image> $images + * @property-read \Tests\Utils\Models\Post|null $parent * @property-read \Illuminate\Database\Eloquent\Collection<\Tests\Utils\Models\RoleUserPivot> $roles + * @property-read \Tests\Utils\Models\PostStatus|null $status + * @property-read \Illuminate\Database\Eloquent\Collection<\Tests\Utils\Models\Tag> $tags + * @property-read \Tests\Utils\Models\Task $task + * @property-read \Tests\Utils\Models\User|null $user */ final class Post extends Model { use Searchable; use SoftDeletes; - /** @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Tests\Utils\Models\User, self> */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } - /** @return \Illuminate\Database\Eloquent\Relations\MorphMany<\Tests\Utils\Models\Activity> */ public function activity(): MorphMany { return $this->morphMany(Activity::class, 'content'); } + /** @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\Tests\Utils\Models\Category> */ + public function categories(): BelongsToMany + { + return $this->belongsToMany(Category::class, 'category_post', 'category_id', 'post_id'); + } + + /** @return \Illuminate\Database\Eloquent\Relations\HasMany */ + public function children(): HasMany + { + return $this->hasMany(self::class); + } + /** @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Utils\Models\Comment> */ public function comments(): HasMany { return $this->hasMany(Comment::class); } - /** @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Tests\Utils\Models\Task, self> */ - public function task(): BelongsTo + /** @return \Illuminate\Database\Eloquent\Relations\MorphMany<\Tests\Utils\Models\Image> */ + public function images(): MorphMany { - return $this->belongsTo(Task::class); + return $this->morphMany(Image::class, 'imageable'); } /** @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -73,33 +84,33 @@ public function parent(): BelongsTo return $this->belongsTo(self::class); } - /** @return \Illuminate\Database\Eloquent\Relations\HasMany */ - public function children(): HasMany + /** @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Utils\Models\RoleUserPivot> */ + public function roles(): HasMany { - return $this->hasMany(self::class); + return $this->hasMany(RoleUserPivot::class, 'user_id', 'user_id'); } - /** @return \Illuminate\Database\Eloquent\Relations\MorphToMany<\Tests\Utils\Models\Tag> */ - public function tags(): MorphToMany + /** @return \Illuminate\Database\Eloquent\Relations\HasOne<\Tests\Utils\Models\PostStatus> */ + public function status(): HasOne { - return $this->morphToMany(Tag::class, 'taggable'); + return $this->hasOne(PostStatus::class); } - /** @return \Illuminate\Database\Eloquent\Relations\MorphMany<\Tests\Utils\Models\Image> */ - public function images(): MorphMany + /** @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Tests\Utils\Models\Task, self> */ + public function task(): BelongsTo { - return $this->morphMany(Image::class, 'imageable'); + return $this->belongsTo(Task::class); } - /** @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\Tests\Utils\Models\Category> */ - public function categories(): BelongsToMany + /** @return \Illuminate\Database\Eloquent\Relations\MorphToMany<\Tests\Utils\Models\Tag> */ + public function tags(): MorphToMany { - return $this->belongsToMany(Category::class, 'category_post', 'category_id', 'post_id'); + return $this->morphToMany(Tag::class, 'taggable'); } - /** @return \Illuminate\Database\Eloquent\Relations\HasMany<\Tests\Utils\Models\RoleUserPivot> */ - public function roles(): HasMany + /** @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Tests\Utils\Models\User, self> */ + public function user(): BelongsTo { - return $this->hasMany(RoleUserPivot::class, 'user_id', 'user_id'); + return $this->belongsTo(User::class); } } diff --git a/tests/Utils/Models/PostStatus.php b/tests/Utils/Models/PostStatus.php new file mode 100644 index 000000000..a3940e81e --- /dev/null +++ b/tests/Utils/Models/PostStatus.php @@ -0,0 +1,29 @@ + */ + public function post(): BelongsTo + { + return $this->belongsTo(Post::class); + } +} diff --git a/tests/Utils/Models/Task.php b/tests/Utils/Models/Task.php index ed0fd7dbc..b55e8c693 100644 --- a/tests/Utils/Models/Task.php +++ b/tests/Utils/Models/Task.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Database\Eloquent\Relations\HasOneThrough; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphToMany; @@ -35,6 +36,8 @@ * @property-read \Tests\Utils\Models\Image $image * @property-read \Illuminate\Database\Eloquent\Collection<\Tests\Utils\Models\Image> $images * @property-read \Tests\Utils\Models\Post|null $post + * @property-read \Tests\Utils\Models\Comment|null $postComments + * @property-read \Tests\Utils\Models\PostStatus|null $postStatus * @property-read \Illuminate\Database\Eloquent\Collection<\Tests\Utils\Models\Tag> $tags * @property-read \Tests\Utils\Models\User|null $user */ @@ -84,6 +87,12 @@ public function postComments(): HasManyThrough return $this->hasManyThrough(Comment::class, Post::class); } + /** @return \Illuminate\Database\Eloquent\Relations\HasOneThrough<\Tests\Utils\Models\PostStatus> */ + public function postStatus(): HasOneThrough + { + return $this->hasOneThrough(PostStatus::class, Post::class, 'task_id', 'post_id'); + } + /** @return \Illuminate\Database\Eloquent\Relations\MorphToMany<\Tests\Utils\Models\Tag> */ public function tags(): MorphToMany { diff --git a/tests/database/factories/CommentFactory.php b/tests/database/factories/CommentFactory.php index 3826a96d1..b6d58da1f 100644 --- a/tests/database/factories/CommentFactory.php +++ b/tests/database/factories/CommentFactory.php @@ -8,6 +8,6 @@ /** @var Illuminate\Database\Eloquent\Factory $factory */ $factory->define(Comment::class, static fn (Faker $faker): array => [ 'comment' => $faker->sentence, - 'user_id' => static fn () => factory(User::class)->create()->getKey(), - 'post_id' => static fn () => factory(Post::class)->create()->getKey(), + 'user_id' => factory(User::class), + 'post_id' => factory(Post::class), ]); diff --git a/tests/database/factories/PostFactory.php b/tests/database/factories/PostFactory.php index af0dd818b..b75f2cf20 100644 --- a/tests/database/factories/PostFactory.php +++ b/tests/database/factories/PostFactory.php @@ -9,7 +9,7 @@ $factory->define(Post::class, static fn (Faker $faker): array => [ 'title' => $faker->title, 'body' => $faker->sentence, - 'user_id' => static fn () => factory(User::class)->create()->getKey(), - 'task_id' => static fn () => factory(Task::class)->create()->getKey(), + 'user_id' => factory(User::class), + 'task_id' => factory(Task::class), 'parent_id' => null, ]); diff --git a/tests/database/factories/ProductFactory.php b/tests/database/factories/ProductFactory.php index b39143e78..6e5827f37 100644 --- a/tests/database/factories/ProductFactory.php +++ b/tests/database/factories/ProductFactory.php @@ -8,6 +8,6 @@ $factory->define(Product::class, static fn (Faker $faker): array => [ 'barcode' => $faker->ean13(), 'uuid' => $faker->uuid, - 'color_id' => static fn () => factory(Color::class)->create()->getKey(), + 'color_id' => factory(Color::class), 'name' => $faker->name, ]); diff --git a/tests/database/factories/RoleFactory.php b/tests/database/factories/RoleFactory.php index 597c81caa..35339f934 100644 --- a/tests/database/factories/RoleFactory.php +++ b/tests/database/factories/RoleFactory.php @@ -7,5 +7,5 @@ /** @var Illuminate\Database\Eloquent\Factory $factory */ $factory->define(Role::class, static fn (Faker $faker): array => [ 'name' => "role_{$faker->unique()->randomNumber()}", - 'acl_id' => static fn () => factory(ACL::class)->create()->getKey(), + 'acl_id' => factory(ACL::class), ]); diff --git a/tests/database/factories/TaskStatusFactory.php b/tests/database/factories/TaskStatusFactory.php new file mode 100644 index 000000000..51eab8db0 --- /dev/null +++ b/tests/database/factories/TaskStatusFactory.php @@ -0,0 +1,8 @@ +define(Tests\Utils\Models\PostStatus::class, static fn (Faker $faker): array => [ + 'status' => $faker->randomElement(['DONE', 'PENDING']), +]); diff --git a/tests/database/factories/UserFactory.php b/tests/database/factories/UserFactory.php index 5f9c385ca..fce868161 100644 --- a/tests/database/factories/UserFactory.php +++ b/tests/database/factories/UserFactory.php @@ -7,8 +7,8 @@ /** @var Illuminate\Database\Eloquent\Factory $factory */ $factory->define(User::class, static fn (Faker $faker): array => [ - 'company_id' => static fn () => factory(Company::class)->create()->getKey(), - 'team_id' => static fn () => factory(Team::class)->create()->getKey(), + 'company_id' => factory(Company::class), + 'team_id' => factory(Team::class), 'name' => $faker->name, 'email' => $faker->unique()->safeEmail, 'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret diff --git a/tests/database/migrations/2018_02_28_000000_create_testbench_companies_table.php b/tests/database/migrations/2018_02_28_000000_create_testbench_companies_table.php index bc9bce079..5247b5e2a 100644 --- a/tests/database/migrations/2018_02_28_000000_create_testbench_companies_table.php +++ b/tests/database/migrations/2018_02_28_000000_create_testbench_companies_table.php @@ -9,10 +9,9 @@ final class CreateTestbenchCompaniesTable extends Migration public function up(): void { Schema::create('companies', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->uuid('uuid')->default('00000000-0000-0000-0000-000000000000'); $table->string('name'); - $table->timestamps(); }); } diff --git a/tests/database/migrations/2018_02_28_000000_create_testbench_images_table.php b/tests/database/migrations/2018_02_28_000000_create_testbench_images_table.php index 62fd913f6..cf0449039 100644 --- a/tests/database/migrations/2018_02_28_000000_create_testbench_images_table.php +++ b/tests/database/migrations/2018_02_28_000000_create_testbench_images_table.php @@ -9,12 +9,10 @@ final class CreateTestbenchImagesTable extends Migration public function up(): void { Schema::create('images', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('url')->nullable(); - - $table->unsignedInteger('imageable_id')->nullable(); + $table->unsignedBigInteger('imageable_id')->nullable(); $table->string('imageable_type')->nullable(); - $table->timestamps(); }); } diff --git a/tests/database/migrations/2018_02_28_000001_create_testbench_teams_table.php b/tests/database/migrations/2018_02_28_000001_create_testbench_teams_table.php index 9a935dee7..e8be99e91 100644 --- a/tests/database/migrations/2018_02_28_000001_create_testbench_teams_table.php +++ b/tests/database/migrations/2018_02_28_000001_create_testbench_teams_table.php @@ -9,9 +9,8 @@ final class CreateTestbenchTeamsTable extends Migration public function up(): void { Schema::create('teams', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('name'); - $table->timestamps(); }); } diff --git a/tests/database/migrations/2018_02_28_000002_create_testbench_users_table.php b/tests/database/migrations/2018_02_28_000002_create_testbench_users_table.php index 375595c2d..b70532971 100644 --- a/tests/database/migrations/2018_02_28_000002_create_testbench_users_table.php +++ b/tests/database/migrations/2018_02_28_000002_create_testbench_users_table.php @@ -18,11 +18,9 @@ public function up(): void $table->string('password')->nullable(); $table->rememberToken(); $table->timestamps(); - - $table->unsignedInteger('company_id')->nullable(); - $table->unsignedInteger('team_id')->nullable(); - - $table->unsignedInteger('person_id')->nullable(); + $table->unsignedBigInteger('company_id')->nullable(); + $table->unsignedBigInteger('team_id')->nullable(); + $table->unsignedBigInteger('person_id')->nullable(); $table->string('person_type')->nullable(); }); } diff --git a/tests/database/migrations/2018_02_28_000002_create_testbench_with_enums_table.php b/tests/database/migrations/2018_02_28_000002_create_testbench_with_enums_table.php index a9cbe0d4d..9923799e8 100644 --- a/tests/database/migrations/2018_02_28_000002_create_testbench_with_enums_table.php +++ b/tests/database/migrations/2018_02_28_000002_create_testbench_with_enums_table.php @@ -9,7 +9,7 @@ final class CreateTestbenchWithEnumsTable extends Migration public function up(): void { Schema::create('with_enums', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('name')->nullable(); $table->enum('type', ['A', 'B'])->nullable(); }); diff --git a/tests/database/migrations/2018_02_28_000003_create_testbench_tasks_table.php b/tests/database/migrations/2018_02_28_000003_create_testbench_tasks_table.php index 4d5cde2bf..e2cb57ecb 100644 --- a/tests/database/migrations/2018_02_28_000003_create_testbench_tasks_table.php +++ b/tests/database/migrations/2018_02_28_000003_create_testbench_tasks_table.php @@ -9,15 +9,13 @@ final class CreateTestbenchTasksTable extends Migration public function up(): void { Schema::create('tasks', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('name')->unique(); $table->string('guard') ->nullable() ->comment('The purpose of this property is to collide with a native model method name'); - $table->unsignedInteger('difficulty')->nullable(); - - $table->unsignedInteger('user_id')->nullable(); - + $table->unsignedBigInteger('difficulty')->nullable(); + $table->unsignedBigInteger('user_id')->nullable(); $table->timestamp('completed_at')->nullable(); $table->timestamps(); $table->softDeletes(); diff --git a/tests/database/migrations/2018_02_28_000004_create_testbench_posts_table.php b/tests/database/migrations/2018_02_28_000004_create_testbench_posts_table.php index b09c1cbee..547db555c 100644 --- a/tests/database/migrations/2018_02_28_000004_create_testbench_posts_table.php +++ b/tests/database/migrations/2018_02_28_000004_create_testbench_posts_table.php @@ -9,14 +9,12 @@ final class CreateTestbenchPostsTable extends Migration public function up(): void { Schema::create('posts', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('title'); $table->string('body')->nullable(); - - $table->unsignedInteger('task_id'); - $table->unsignedInteger('user_id')->nullable(); - $table->unsignedInteger('parent_id')->nullable(); - + $table->unsignedBigInteger('task_id'); + $table->unsignedBigInteger('user_id')->nullable(); + $table->unsignedBigInteger('parent_id')->nullable(); $table->timestamps(); $table->softDeletes(); }); diff --git a/tests/database/migrations/2018_02_28_000005_create_testbench_comments_table.php b/tests/database/migrations/2018_02_28_000005_create_testbench_comments_table.php index 8323c45df..ac5f3f959 100644 --- a/tests/database/migrations/2018_02_28_000005_create_testbench_comments_table.php +++ b/tests/database/migrations/2018_02_28_000005_create_testbench_comments_table.php @@ -9,12 +9,10 @@ final class CreateTestbenchCommentsTable extends Migration public function up(): void { Schema::create('comments', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('comment'); - - $table->unsignedInteger('user_id'); - $table->unsignedInteger('post_id'); - + $table->unsignedBigInteger('user_id'); + $table->unsignedBigInteger('post_id'); $table->timestamps(); }); } diff --git a/tests/database/migrations/2018_09_30_000006_create_testbench_tags_table.php b/tests/database/migrations/2018_09_30_000006_create_testbench_tags_table.php index 4af1009e9..24d230b11 100644 --- a/tests/database/migrations/2018_09_30_000006_create_testbench_tags_table.php +++ b/tests/database/migrations/2018_09_30_000006_create_testbench_tags_table.php @@ -10,10 +10,9 @@ final class CreateTestbenchTagsTable extends Migration public function up(): void { Schema::create('tags', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('name'); $table->string('default_string')->default(Constants::TAGS_DEFAULT_STRING); - $table->timestamps(); }); } diff --git a/tests/database/migrations/2018_09_30_000007_create_testbench_taggables_table.php b/tests/database/migrations/2018_09_30_000007_create_testbench_taggables_table.php index c92b90f7c..6357eb189 100644 --- a/tests/database/migrations/2018_09_30_000007_create_testbench_taggables_table.php +++ b/tests/database/migrations/2018_09_30_000007_create_testbench_taggables_table.php @@ -9,11 +9,9 @@ final class CreateTestbenchTaggablesTable extends Migration public function up(): void { Schema::create('taggables', function (Blueprint $table): void { - $table->unsignedInteger('tag_id'); - - $table->unsignedInteger('taggable_id'); + $table->unsignedBigInteger('tag_id'); + $table->unsignedBigInteger('taggable_id'); $table->string('taggable_type'); - $table->timestamps(); }); } diff --git a/tests/database/migrations/2018_10_07_000008_create_testbench_acls_table.php b/tests/database/migrations/2018_10_07_000008_create_testbench_acls_table.php index 65dec6d81..f7bed21ac 100644 --- a/tests/database/migrations/2018_10_07_000008_create_testbench_acls_table.php +++ b/tests/database/migrations/2018_10_07_000008_create_testbench_acls_table.php @@ -9,7 +9,7 @@ final class CreateTestbenchAclsTable extends Migration public function up(): void { Schema::create('acls', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->boolean('create_post'); $table->boolean('read_post'); $table->boolean('update_post'); diff --git a/tests/database/migrations/2018_10_07_000009_create_testbench_roles_table.php b/tests/database/migrations/2018_10_07_000009_create_testbench_roles_table.php index 837cfe444..af97f0060 100644 --- a/tests/database/migrations/2018_10_07_000009_create_testbench_roles_table.php +++ b/tests/database/migrations/2018_10_07_000009_create_testbench_roles_table.php @@ -9,10 +9,9 @@ final class CreateTestbenchRolesTable extends Migration public function up(): void { Schema::create('roles', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('name'); - - $table->unsignedInteger('acl_id')->nullable(); + $table->unsignedBigInteger('acl_id')->nullable(); }); } diff --git a/tests/database/migrations/2018_10_07_000010_create_testbench_role_user_table.php b/tests/database/migrations/2018_10_07_000010_create_testbench_role_user_table.php index f485a4277..c4d9330b8 100644 --- a/tests/database/migrations/2018_10_07_000010_create_testbench_role_user_table.php +++ b/tests/database/migrations/2018_10_07_000010_create_testbench_role_user_table.php @@ -9,11 +9,10 @@ final class CreateTestbenchRoleUserTable extends Migration public function up(): void { Schema::create('role_user', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('meta')->nullable(); - - $table->unsignedInteger('user_id'); - $table->unsignedInteger('role_id'); + $table->unsignedBigInteger('user_id'); + $table->unsignedBigInteger('role_id'); }); } diff --git a/tests/database/migrations/2018_11_25_000004_create_testbench_colors_table.php b/tests/database/migrations/2018_11_25_000004_create_testbench_colors_table.php index 2a83905fd..133ecfc11 100644 --- a/tests/database/migrations/2018_11_25_000004_create_testbench_colors_table.php +++ b/tests/database/migrations/2018_11_25_000004_create_testbench_colors_table.php @@ -9,12 +9,10 @@ final class CreateTestbenchColorsTable extends Migration public function up(): void { Schema::create('colors', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('name'); - - $table->unsignedInteger('creator_id')->nullable(); + $table->unsignedBigInteger('creator_id')->nullable(); $table->string('creator_type')->nullable(); - $table->timestamps(); }); } diff --git a/tests/database/migrations/2018_11_25_000005_create_testbench_products_table.php b/tests/database/migrations/2018_11_25_000005_create_testbench_products_table.php index 7705b8af8..000e19b64 100644 --- a/tests/database/migrations/2018_11_25_000005_create_testbench_products_table.php +++ b/tests/database/migrations/2018_11_25_000005_create_testbench_products_table.php @@ -12,11 +12,8 @@ public function up(): void // Composite primary key $table->string('barcode'); $table->string('uuid'); - $table->string('name'); - - $table->unsignedInteger('color_id'); - + $table->unsignedBigInteger('color_id'); $table->timestamps(); }); } diff --git a/tests/database/migrations/2018_12_08_000001_create_testbench_categories_table.php b/tests/database/migrations/2018_12_08_000001_create_testbench_categories_table.php index a301f93ab..8338170cd 100644 --- a/tests/database/migrations/2018_12_08_000001_create_testbench_categories_table.php +++ b/tests/database/migrations/2018_12_08_000001_create_testbench_categories_table.php @@ -9,11 +9,9 @@ final class CreateTestbenchCategoriesTable extends Migration public function up(): void { Schema::create('categories', function (Blueprint $table): void { - $table->increments('category_id'); + $table->id('category_id'); $table->string('name'); - - $table->unsignedInteger('parent_id')->nullable(); - + $table->unsignedBigInteger('parent_id')->nullable(); $table->timestamps(); }); } diff --git a/tests/database/migrations/2019_11_04_000001_create_testbench_contractors_table.php b/tests/database/migrations/2019_11_04_000001_create_testbench_contractors_table.php index cdf63dfe0..7276fefe0 100644 --- a/tests/database/migrations/2019_11_04_000001_create_testbench_contractors_table.php +++ b/tests/database/migrations/2019_11_04_000001_create_testbench_contractors_table.php @@ -9,9 +9,8 @@ final class CreateTestbenchContractorsTable extends Migration public function up(): void { Schema::create('contractors', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('position'); - $table->timestamps(); }); } diff --git a/tests/database/migrations/2019_11_04_000001_create_testbench_employees_table.php b/tests/database/migrations/2019_11_04_000001_create_testbench_employees_table.php index 88b5f758c..aa6e44b3c 100644 --- a/tests/database/migrations/2019_11_04_000001_create_testbench_employees_table.php +++ b/tests/database/migrations/2019_11_04_000001_create_testbench_employees_table.php @@ -9,9 +9,8 @@ final class CreateTestbenchEmployeesTable extends Migration public function up(): void { Schema::create('employees', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('position'); - $table->timestamps(); }); } diff --git a/tests/database/migrations/2020_07_09_000000_create_testbench_activities_table.php b/tests/database/migrations/2020_07_09_000000_create_testbench_activities_table.php index a2a1dd018..e6669ea38 100644 --- a/tests/database/migrations/2020_07_09_000000_create_testbench_activities_table.php +++ b/tests/database/migrations/2020_07_09_000000_create_testbench_activities_table.php @@ -9,11 +9,9 @@ final class CreateTestbenchActivitiesTable extends Migration public function up(): void { Schema::create('activities', function (Blueprint $table): void { - $table->increments('id'); - - $table->unsignedInteger('user_id'); + $table->id(); + $table->unsignedBigInteger('user_id'); $table->morphs('content'); - $table->timestamps(); }); } diff --git a/tests/database/migrations/2021_01_30_000000_create_testbench_category_post_table.php b/tests/database/migrations/2021_01_30_000000_create_testbench_category_post_table.php index 4b3d15bab..fd49f08f8 100644 --- a/tests/database/migrations/2021_01_30_000000_create_testbench_category_post_table.php +++ b/tests/database/migrations/2021_01_30_000000_create_testbench_category_post_table.php @@ -9,10 +9,9 @@ final class CreateTestbenchCategoryPostTable extends Migration public function up(): void { Schema::create('category_post', function (Blueprint $table): void { - $table->increments('id'); - - $table->unsignedInteger('category_id'); - $table->unsignedInteger('post_id'); + $table->id(); + $table->unsignedBigInteger('category_id'); + $table->unsignedBigInteger('post_id'); }); } diff --git a/tests/database/migrations/2021_04_14_000000_create_testbench_alternate_connections_table.php b/tests/database/migrations/2021_04_14_000000_create_testbench_alternate_connections_table.php index cf37ca76b..bb6c81aa0 100644 --- a/tests/database/migrations/2021_04_14_000000_create_testbench_alternate_connections_table.php +++ b/tests/database/migrations/2021_04_14_000000_create_testbench_alternate_connections_table.php @@ -9,9 +9,8 @@ final class CreateTestbenchAlternateConnectionsTable extends Migration public function up(): void { Schema::create('alternate_connections', function (Blueprint $table): void { - $table->increments('id'); - - $table->unsignedInteger('user_id')->nullable(); + $table->id(); + $table->unsignedBigInteger('user_id')->nullable(); }); } diff --git a/tests/database/migrations/2021_04_14_000000_create_testbench_locations_table.php b/tests/database/migrations/2021_04_14_000000_create_testbench_locations_table.php index bd5b57d51..fadc08869 100644 --- a/tests/database/migrations/2021_04_14_000000_create_testbench_locations_table.php +++ b/tests/database/migrations/2021_04_14_000000_create_testbench_locations_table.php @@ -9,11 +9,9 @@ final class CreateTestbenchLocationsTable extends Migration public function up(): void { Schema::create('locations', function (Blueprint $table): void { - $table->increments('id'); - - $table->unsignedInteger('parent_id')->nullable(); + $table->id(); + $table->unsignedBigInteger('parent_id')->nullable(); $table->json('extra')->nullable(); - $table->timestamps(); }); } diff --git a/tests/database/migrations/2022_04_14_000000_create_testbench_custom_primary_keys_table.php b/tests/database/migrations/2022_04_14_000000_create_testbench_custom_primary_keys_table.php index 96c4365a0..7cc31de49 100644 --- a/tests/database/migrations/2022_04_14_000000_create_testbench_custom_primary_keys_table.php +++ b/tests/database/migrations/2022_04_14_000000_create_testbench_custom_primary_keys_table.php @@ -9,9 +9,8 @@ final class CreateTestbenchCustomPrimaryKeysTable extends Migration public function up(): void { Schema::create('custom_primary_keys', function (Blueprint $table): void { - $table->increments('custom_primary_key_id'); - - $table->unsignedInteger('user_id')->nullable(); + $table->id('custom_primary_key_id'); + $table->unsignedBigInteger('user_id')->nullable(); }); } diff --git a/tests/database/migrations/2022_04_21_000000_create_testbench_null_connections_table.php b/tests/database/migrations/2022_04_21_000000_create_testbench_null_connections_table.php index 9efeef153..a71bedbe6 100644 --- a/tests/database/migrations/2022_04_21_000000_create_testbench_null_connections_table.php +++ b/tests/database/migrations/2022_04_21_000000_create_testbench_null_connections_table.php @@ -9,7 +9,7 @@ final class CreateTestbenchNullConnectionsTable extends Migration public function up(): void { Schema::create('null_connections', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); }); } diff --git a/tests/database/migrations/2023_09_30_000006_create_testbench_podcasts_table.php b/tests/database/migrations/2023_09_30_000006_create_testbench_podcasts_table.php index 441d74b44..3dd964d1a 100644 --- a/tests/database/migrations/2023_09_30_000006_create_testbench_podcasts_table.php +++ b/tests/database/migrations/2023_09_30_000006_create_testbench_podcasts_table.php @@ -9,7 +9,7 @@ final class CreateTestbenchPodcastsTable extends Migration public function up(): void { Schema::create('podcasts', function (Blueprint $table): void { - $table->increments('id'); + $table->id(); $table->string('title'); $table->timestamp('schedule_at')->nullable(); $table->softDeletes(); diff --git a/tests/database/migrations/2024_07_15_000009_create_testbench_post_statuses_table.php b/tests/database/migrations/2024_07_15_000009_create_testbench_post_statuses_table.php new file mode 100644 index 000000000..bb47a98c7 --- /dev/null +++ b/tests/database/migrations/2024_07_15_000009_create_testbench_post_statuses_table.php @@ -0,0 +1,24 @@ +id(); + $table->enum('status', ['DONE', 'PENDING']); + $table->unsignedBigInteger('post_id'); + $table->softDeletes(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::drop('post_statuses'); + } +}