<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;

class WikiSectionNameMigration extends Migration
{


    public function up()
    {
        $sections = $this->db->table('wiki_sections')->select()->get()->getResultArray();
        $this->forge->dropColumn('wiki_sections','name');
        $this->forge->addColumn('wiki_sections',[
            'name' => [
                'type' => 'LONGTEXT',
                'null' => false,
            ]
        ]);
        foreach ($sections as $key => $value) {
            $this->db->table('wiki_sections')->update(
                [
                    "name" => json_encode(["es" => $value['name'],"en" => $value['name']])
                ],
                'id = '.$value['id']
            );
        }
    }

    public function down()
    {

    }
}
