From f47588af858e571d14e93838f11836e5490641fb Mon Sep 17 00:00:00 2001 From: Watheq Alshowaiter Date: Sun, 14 Jul 2024 16:58:50 +0300 Subject: [PATCH] refactor: improve migration and model names --- ... => 2024_07_13_090447_create_fathers_table.php} | 2 +- ... => 2024_07_13_093048_create_mothers_table.php} | 2 +- ...php => 2024_07_13_100247_create_sons_table.php} | 5 +++-- src/Models/{ChildTestModel.php => Father.php} | 2 +- src/Models/{ParentTestModel.php => Mother.php} | 2 +- src/Models/{AnotherParentTestModel.php => Son.php} | 2 +- tests/RequiredFieldsTest.php | 14 +++++++------- 7 files changed, 15 insertions(+), 14 deletions(-) rename database/migrations/{2024_07_13_090447_create_parent_test_models_table.php => 2024_07_13_090447_create_fathers_table.php} (91%) rename database/migrations/{2024_07_13_093048_create_another_parent_test_models_table.php => 2024_07_13_093048_create_mothers_table.php} (88%) rename database/migrations/{2024_07_13_100247_create_child_test_models_table.php => 2024_07_13_100247_create_sons_table.php} (64%) rename src/Models/{ChildTestModel.php => Father.php} (84%) rename src/Models/{ParentTestModel.php => Mother.php} (84%) rename src/Models/{AnotherParentTestModel.php => Son.php} (81%) diff --git a/database/migrations/2024_07_13_090447_create_parent_test_models_table.php b/database/migrations/2024_07_13_090447_create_fathers_table.php similarity index 91% rename from database/migrations/2024_07_13_090447_create_parent_test_models_table.php rename to database/migrations/2024_07_13_090447_create_fathers_table.php index bdf8576..71583bd 100644 --- a/database/migrations/2024_07_13_090447_create_parent_test_models_table.php +++ b/database/migrations/2024_07_13_090447_create_fathers_table.php @@ -8,7 +8,7 @@ { public function up(): void { - Schema::create('parent_test_models', function (Blueprint $table) { + Schema::create('fathers', function (Blueprint $table) { $table->id(); // primary key -> ignored $table->boolean('active')->default(false); // default => ignored $table->string('name'); // required diff --git a/database/migrations/2024_07_13_093048_create_another_parent_test_models_table.php b/database/migrations/2024_07_13_093048_create_mothers_table.php similarity index 88% rename from database/migrations/2024_07_13_093048_create_another_parent_test_models_table.php rename to database/migrations/2024_07_13_093048_create_mothers_table.php index 9e85899..c9b1142 100644 --- a/database/migrations/2024_07_13_093048_create_another_parent_test_models_table.php +++ b/database/migrations/2024_07_13_093048_create_mothers_table.php @@ -8,7 +8,7 @@ { public function up(): void { - Schema::create('another_parent_test_models', function (Blueprint $table) { + Schema::create('mothers', function (Blueprint $table) { $table->ulid('id')->primary(); // primary key => ignored $table->enum('types', ['one', 'two'])->default('one'); // default => ignored $table->uuid('uuid'); // required diff --git a/database/migrations/2024_07_13_100247_create_child_test_models_table.php b/database/migrations/2024_07_13_100247_create_sons_table.php similarity index 64% rename from database/migrations/2024_07_13_100247_create_child_test_models_table.php rename to database/migrations/2024_07_13_100247_create_sons_table.php index 35f05ba..18c5d8d 100644 --- a/database/migrations/2024_07_13_100247_create_child_test_models_table.php +++ b/database/migrations/2024_07_13_100247_create_sons_table.php @@ -8,10 +8,11 @@ { public function up(): void { - Schema::create('child_test_models', function (Blueprint $table) { + Schema::create('sons', function (Blueprint $table) { $table->uuid('id')->primary(); // primary key => ignored $table->foreignId('parent_id')->constrained(); // required - $table->foreignUlid('another_parent_id')->nullable()->constrained(); // nullable => ignored + $table->foreignUlid('mother_id')->nullable()->constrained(); // nullable => ignored + $table->foreignId('father_id')->nullable()->constrained(); // nullable => ignored }); } diff --git a/src/Models/ChildTestModel.php b/src/Models/Father.php similarity index 84% rename from src/Models/ChildTestModel.php rename to src/Models/Father.php index af66a27..31921c4 100644 --- a/src/Models/ChildTestModel.php +++ b/src/Models/Father.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; use WatheqAlshowaiter\ModelRequiredFields\RequiredFields; -class ChildTestModel extends Model +class Father extends Model { use RequiredFields; } diff --git a/src/Models/ParentTestModel.php b/src/Models/Mother.php similarity index 84% rename from src/Models/ParentTestModel.php rename to src/Models/Mother.php index ed04873..9a2dbbf 100644 --- a/src/Models/ParentTestModel.php +++ b/src/Models/Mother.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; use WatheqAlshowaiter\ModelRequiredFields\RequiredFields; -class ParentTestModel extends Model +class Mother extends Model { use RequiredFields; } diff --git a/src/Models/AnotherParentTestModel.php b/src/Models/Son.php similarity index 81% rename from src/Models/AnotherParentTestModel.php rename to src/Models/Son.php index c4db3c9..71752e7 100644 --- a/src/Models/AnotherParentTestModel.php +++ b/src/Models/Son.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; use WatheqAlshowaiter\ModelRequiredFields\RequiredFields; -class AnotherParentTestModel extends Model +class Son extends Model { use RequiredFields; } diff --git a/tests/RequiredFieldsTest.php b/tests/RequiredFieldsTest.php index 7e73012..426d409 100644 --- a/tests/RequiredFieldsTest.php +++ b/tests/RequiredFieldsTest.php @@ -1,9 +1,9 @@ assertEquals([ 'name', 'email', - ], ParentTestModel::getRequiredFields()); + ], Father::getRequiredFields()); $this->assertNotEquals([ 'email', 'name', - ], ParentTestModel::getRequiredFields()); + ], Father::getRequiredFields()); } public function test_get_required_fields_for_another_parent_model() @@ -28,13 +28,13 @@ public function test_get_required_fields_for_another_parent_model() $this->assertEquals([ 'uuid', 'ulid', - ], AnotherParentTestModel::getRequiredFields()); + ], Mother::getRequiredFields()); } public function test_get_required_fields_for_child_model() { $this->assertEquals([ 'parent_id', - ], ChildTestModel::getRequiredFields()); + ], Son::getRequiredFields()); } }