p
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user