This commit is contained in:
lizandrogd
2026-01-19 22:34:13 -05:00
parent f127532d7b
commit 175b10dcf8
4 changed files with 80 additions and 2 deletions
@@ -0,0 +1,21 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
// Backfill producto_id in inventario_prendas from la OP relacionada cuando sea NULL
DB::statement("UPDATE inventario_prendas ip SET producto_id = op.producto_id FROM orden_produccions op WHERE ip.orden_produccion_id = op.id AND ip.producto_id IS NULL AND op.producto_id IS NOT NULL");
}
public function down(): void
{
// Revertir sólo las asignaciones que coinciden con la OP actual
DB::statement("UPDATE inventario_prendas ip SET producto_id = NULL FROM orden_produccions op WHERE ip.orden_produccion_id = op.id AND ip.producto_id = op.producto_id");
}
};