<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Migration_Version_621 extends CI_Migration
{
    public function __construct()
    {
        parent::__construct();
    }

    public function up()
    {
        $this->upsert_config('version', '6.2.1');
    }

    public function down()
    {
        $this->upsert_config('version', '6.2.0');
    }

    private function upsert_config($key, $value)
    {
        if (!$this->db->table_exists('tbl_config')) {
            return;
        }

        $exists = $this->db->where('config_key', $key)->get('tbl_config')->row();
        if ($exists) {
            $this->db->where('config_key', $key)->update('tbl_config', array('value' => $value));
            return;
        }

        $this->db->insert('tbl_config', array(
            'config_key' => $key,
            'value' => $value,
        ));
    }
}
