<?php

use Schema\Wrapper as Wrapper;
use App\Core\Sanity\MigratorController as Migrator;

function geo_country_upgrade($pluginversion) {
    if ($pluginversion < "0.0.1") {
        $table = Wrapper::get_table("geo_countries");
        $table->addSoftDelete();
        $table->addColumn("name",        "string",  Array("null" => false));
        $table->addColumn("description", "string",  Array("null" => true));
        $table->addColumn("code",        "integer", Array("null" => false));
        $table->addColumn("iso2",        "string",  Array("null" => false, 'limit' => 2));
        $table->addColumn("iso3",        "string",  Array("null" => false, 'limit' => 3));        
        $table->save();
        
        Wrapper::exec(file_get_contents(__DIR__.'/001_countries_seeding.sql') );
        
        Migrator::getInstance()->update_plugin_version("geo_country", "1.0.0");
        return;
    }

    //if ($pluginversion < "0.0.2") {
        //$table = Wrapper::get_table("geo_country");
        //Migrator::getInstance()->update_plugin_version("geo_country", "1.0.1");
        //return;
    //}
}

function geo_country_rollback($pluginversion) {
    if($pluginversion > "0.0.1"){
        $table = Wrapper::get_table("geo_countries");
        $table->drop();
        return;
    }
}