This commit is contained in:
lizandrogd
2026-01-19 23:10:13 -05:00
parent 674bf82309
commit 9f903887b9
5 changed files with 105 additions and 4 deletions
@@ -10,7 +10,19 @@ 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");
// Use a compatible update for both MySQL/Postgres and SQLite
$driver = Schema::getConnection()->getDriverName();
if ($driver === 'sqlite') {
DB::statement(
"UPDATE inventario_prendas SET producto_id = (
SELECT op.producto_id FROM orden_produccions op WHERE op.id = inventario_prendas.orden_produccion_id
) WHERE producto_id IS NULL AND orden_produccion_id IS NOT NULL AND (
SELECT op.producto_id FROM orden_produccions op WHERE op.id = inventario_prendas.orden_produccion_id
) IS NOT NULL"
);
} else {
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