<?php

namespace Lucent\Commands;

use Illuminate\Console\Command;
use Lucent\Database\Database;

class UpgradeFiles122 extends Command
{

    protected $signature = 'lucent:upgrade:files_1_2_2 {schema} {disk}';
    protected $description = 'Upgrade to the new filesystem';


    public function handle()
    {
        $schema =  $this->argument('schema');
        $disk =  $this->argument('disk');
        $db = Database::make();
        $records = $db->table("records")->where("schema", $schema)->get();
        foreach ($records as $record) {
            $array = json_decode($record->_file, true);
            $array["disk"] = $disk;
            $db->table("records")->where("id", $record->id)->update(["_file" => json_encode($array)]);
        }
    }
}
