Procházet zdrojové kódy

migartion data_pagamenti fix

FabioFratini před 9 měsíci
rodič
revize
c1695c34fc

+ 47 - 0
database/migrations/2025_04_09_000002_add_data_pagamento_values_to_records_table.php

@@ -0,0 +1,47 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+
+return new class extends Migration {
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+
+            DB::statement("
+                UPDATE records
+                SET data_pagamento = CASE
+                    WHEN date IS NOT NULL THEN date
+                    ELSE CURRENT_DATE()
+                END
+                WHERE data_pagamento IS NULL AND type='OUT'
+            ");
+
+            // Log the number of updated rows
+            $updatedRows = DB::select("
+                SELECT COUNT(*) as count FROM records
+                WHERE data_pagamento IS NOT NULL AND type='OUT'
+            ");
+            Log::info('Updated data_pagamento for OUT records: ' . $updatedRows[0]->count);
+
+
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        // No need to revert the data updates, but you could if needed
+        // In this case, we won't roll back the data fixes
+    }
+};