<?php

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

//https://book.cakephp.org/phinx/0/en/migrations.html#valid-column-types
function common_glossary_upgrade($pluginversion) {
    if ($pluginversion < "0.0.1") {
        $table = Wrapper::get_table("common_glossarys");
        $table->addColumn("area_id",     "integer", Array("null" => false));
        $table->addColumn("name",        "string", Array("null" => false));
        $table->addColumn("description", "text",   Array("null" => true));
        //$table->addColumn("time", "timestamp", Array("null" => true, "default"=>null));

        $table->addTimestamps();
        $table->addSoftDelete();
        $table->create();

        Migrator::getInstance()->update_plugin_version("common_glossary", "1.0.0");
        return;
    }

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

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