فهرست منبع

feat: adiciona inhabitant class seeder

ebagabee 1 ماه پیش
والد
کامیت
05687a411d

+ 9 - 4
app/Models/InhabitantClassification.php

@@ -8,16 +8,20 @@
 /**
  * @property int $id
  * @property string $description
- * @property string $acronym
+ * @property int $start
+ * @property int $end
+ * @property numeric $tbr_percentage
  * @property \Illuminate\Support\Carbon|null $created_at
  * @property \Illuminate\Support\Carbon|null $updated_at
  * @method static \Illuminate\Database\Eloquent\Builder<static>|InhabitantClassification newModelQuery()
  * @method static \Illuminate\Database\Eloquent\Builder<static>|InhabitantClassification newQuery()
  * @method static \Illuminate\Database\Eloquent\Builder<static>|InhabitantClassification query()
- * @method static \Illuminate\Database\Eloquent\Builder<static>|InhabitantClassification whereAcronym($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|InhabitantClassification whereCreatedAt($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|InhabitantClassification whereDescription($value)
+ * @method static \Illuminate\Database\Eloquent\Builder<static>|InhabitantClassification whereEnd($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|InhabitantClassification whereId($value)
+ * @method static \Illuminate\Database\Eloquent\Builder<static>|InhabitantClassification whereStart($value)
+ * @method static \Illuminate\Database\Eloquent\Builder<static>|InhabitantClassification whereTbrPercentage($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|InhabitantClassification whereUpdatedAt($value)
  * @mixin \Eloquent
  */
@@ -30,7 +34,8 @@ class InhabitantClassification extends Model
     protected $guarded = ['id'];
 
     protected $casts = [
-        'created_at' => 'datetime',
-        'updated_at' => 'datetime',
+        'tbr_percentage' => 'decimal:4',
+        'created_at'     => 'datetime',
+        'updated_at'     => 'datetime',
     ];
 }

+ 9 - 4
app/Models/UnitInhabitantClassification.php

@@ -10,16 +10,20 @@
  * @property int $id
  * @property int $unit_id
  * @property string $description
- * @property string $acronym
+ * @property int $start
+ * @property int $end
+ * @property numeric $tbr_percentage
  * @property \Illuminate\Support\Carbon|null $created_at
  * @property \Illuminate\Support\Carbon|null $updated_at
  * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification newModelQuery()
  * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification newQuery()
  * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification query()
- * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification whereAcronym($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification whereCreatedAt($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification whereDescription($value)
+ * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification whereEnd($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification whereId($value)
+ * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification whereStart($value)
+ * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification whereTbrPercentage($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification whereUnitId($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|UnitInhabitantClassification whereUpdatedAt($value)
  * @mixin \Eloquent
@@ -33,8 +37,9 @@ class UnitInhabitantClassification extends Model
     protected $guarded = ['id'];
 
     protected $casts = [
-        'created_at' => 'datetime',
-        'updated_at' => 'datetime',
+        'tbr_percentage' => 'decimal:4',
+        'created_at'     => 'datetime',
+        'updated_at'     => 'datetime',
     ];
 
     public function unit(): BelongsTo

+ 4 - 4
database/migrations/2026_05_06_180111_update_inhabitant_classifications_table.php

@@ -23,7 +23,7 @@ public function up(): void
             $table->decimal('tbr_percentage', 5, 4)
                 ->nullable();
 
-            $table->unique(['start', 'end']);
+            $table->unique(['description', 'start', 'end']);
         });
 
         Schema::table('unit_inhabitant_classifications', function (Blueprint $table) {
@@ -41,14 +41,14 @@ public function up(): void
             $table->decimal('tbr_percentage', 5, 4)
                 ->nullable();
 
-            $table->unique(['unit_id', 'start', 'end']);
+            $table->unique(['unit_id', 'description', 'start', 'end']);
         });
     }
 
     public function down(): void
     {
         Schema::table('inhabitant_classifications', function (Blueprint $table) {
-            $table->dropUnique(['start', 'end']);
+            $table->dropUnique(['description', 'start', 'end']);
             $table->dropColumn(['start', 'end', 'tbr_percentage']);
 
             $table->string('acronym', 2)
@@ -57,7 +57,7 @@ public function down(): void
         });
 
         Schema::table('unit_inhabitant_classifications', function (Blueprint $table) {
-            $table->dropUnique(['unit_id', 'start', 'end']);
+            $table->dropUnique(['unit_id', 'description', 'start', 'end']);
             $table->dropColumn(['start', 'end', 'tbr_percentage']);
 
             $table->string('acronym', 2)->after('description')->nullable();

+ 13 - 7
database/seeders/InhabitantClassificationSeeder.php

@@ -10,17 +10,23 @@ class InhabitantClassificationSeeder extends Seeder
     public function run(): void
     {
         $classifications = [
-            ['acronym' => 'P1', 'description' => 'Até 30.000 habitantes'],
-            ['acronym' => 'P2', 'description' => 'De 30.001 a 70.000 habitantes'],
-            ['acronym' => 'M1', 'description' => 'De 70.001 a 150.000 habitantes'],
-            ['acronym' => 'M2', 'description' => 'De 150.001 a 300.000 habitantes'],
-            ['acronym' => 'G1', 'description' => 'De 300.001 a 500.000 habitantes'],
-            ['acronym' => 'G2', 'description' => 'Acima de 500.000 habitantes'],
+            ['description' => '50k',         'start' => 1,  'end' => 3,  'tbr_percentage' => 0.0000],
+            ['description' => '50k',         'start' => 4,  'end' => 12, 'tbr_percentage' => 0.4000],
+            ['description' => '50k',         'start' => 13, 'end' => 60, 'tbr_percentage' => 0.6000],
+            ['description' => '50k - 100k',  'start' => 1,  'end' => 3,  'tbr_percentage' => 0.0000],
+            ['description' => '50k - 100k',  'start' => 4,  'end' => 12, 'tbr_percentage' => 0.5000],
+            ['description' => '50k - 100k',  'start' => 13, 'end' => 60, 'tbr_percentage' => 0.7500],
+            ['description' => '100k - 200k', 'start' => 1,  'end' => 3,  'tbr_percentage' => 0.0000],
+            ['description' => '100k - 200k', 'start' => 4,  'end' => 12, 'tbr_percentage' => 0.7500],
+            ['description' => '100k - 200k', 'start' => 13, 'end' => 60, 'tbr_percentage' => 0.1000],
+            ['description' => '> 200k',      'start' => 1,  'end' => 3,  'tbr_percentage' => 0.0000],
+            ['description' => '> 200k',      'start' => 4,  'end' => 12, 'tbr_percentage' => 1.0000],
+            ['description' => '> 200k',      'start' => 13, 'end' => 60, 'tbr_percentage' => 1.5000],
         ];
 
         foreach ($classifications as $item) {
             InhabitantClassification::firstOrCreate(
-                ['acronym' => $item['acronym']],
+                ['description' => $item['description'], 'start' => $item['start'], 'end' => $item['end']],
                 $item,
             );
         }