LD 5 gadi atpakaļ
vecāks
revīzija
93f7b9e1ab

+ 1 - 1
app/Services/StationTaskService.php

@@ -55,7 +55,7 @@ class StationTaskService
                     'station_task_table_type' => $tableName,
                     'station_task_table_id' => $subTask['id'],
                 ];
-                $taskChild_existed=$this->stationTaskChildService->get($paramToInsert)->frist();
+                $taskChild_existed=$this->stationTaskChildService->get($paramToInsert)->first();
                 if(!$taskChild_existed)
                     $taskChildren_toInsert->push($paramToInsert);
             }

+ 17 - 9
database/migrations/2020_12_07_114158_create_station_task_children.php

@@ -21,10 +21,14 @@ class CreateStationTaskChildren extends Migration
             $table->index('station_task_table_id','station_task_table_type');
             $table->timestamps();
         });
-        Schema::table('station_tasks', function (Blueprint $table) {
-            $table->dropIndex('station_taskable_type');
-            $table->dropColumn('station_taskable_type');
-            $table->dropColumn('station_taskable_id');
+        Schema::table('station_task_batches', function (Blueprint $table) {
+            $table->dropColumn('station_id');
+        });
+        Schema::table('station_task_commodities', function (Blueprint $table) {
+            $table->dropColumn('station_id');
+        });
+        Schema::table('station_task_material_boxes', function (Blueprint $table) {
+            $table->dropColumn('station_id');
         });
     }
 
@@ -35,11 +39,15 @@ class CreateStationTaskChildren extends Migration
      */
     public function down()
     {
-        Schema::dropIfExists('station_task_children');
-        Schema::table('station_tasks', function (Blueprint $table) {
-            $table->string('station_taskable_type');
-            $table->integer('station_taskable_id');
-            $table->index(['station_taskable_id','station_taskable_id'],'station_taskable_type');
+        Schema::table('station_task_batches', function (Blueprint $table) {
+            $table->integer('station_id')->index();
         });
+        Schema::table('station_task_commodities', function (Blueprint $table) {
+            $table->integer('station_id')->index();
+        });
+        Schema::table('station_task_material_boxes', function (Blueprint $table) {
+            $table->integer('station_id')->index();
+        });
+        Schema::dropIfExists('station_task_children');
     }
 }

+ 45 - 0
database/migrations/2021_01_06_114158_create_station_task_children2.php

@@ -0,0 +1,45 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateStationTaskChildren2 extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('station_task_children', function (Blueprint $table) {
+            $table->id();
+            $table->bigInteger('station_task_id')->index();
+            $table->string('station_task_table_type');
+            $table->bigInteger('station_task_table_id');
+            $table->index('station_task_table_id','station_task_table_type');
+            $table->timestamps();
+        });
+        Schema::table('station_tasks', function (Blueprint $table) {
+            $table->dropIndex('station_taskable_type');
+            $table->dropColumn('station_taskable_type');
+            $table->dropColumn('station_taskable_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('station_task_children');
+        Schema::table('station_tasks', function (Blueprint $table) {
+            $table->string('station_taskable_type');
+            $table->integer('station_taskable_id');
+            $table->index(['station_taskable_id','station_taskable_id'],'station_taskable_type');
+        });
+    }
+}

+ 2 - 0
tests/Services/StationTaskBatchService/CreateByBatchesTest.php

@@ -9,6 +9,7 @@ use App\Services\StationTaskService;
 use App\StationRuleBatch;
 use App\StationTask;
 use App\StationTaskBatch;
+use App\StationTaskChild;
 use App\StationType;
 use Tests\TestCase;
 
@@ -61,6 +62,7 @@ class CreateByBatchesTest extends TestCase
         Batch::query()->whereIn('id',data_get($this->data['batches'],'*.id')??[])->delete();
         StationTask::query()->whereIn('id',data_get($this->data['stationTasks'],'*.id')??[])->delete();
         StationTaskBatch::query()->whereIn('id',data_get($this->data['stationTaskBatches'],'*.id')??[])->delete();
+        StationTaskChild::query()->whereIn('station_task_id',data_get($this->data['stationTaskBatches'],'*.id')??[])->delete();
         Owner::query()->where('id',$this->data['owner']['id']??'')->delete();
         parent::tearDown();
     }