<?php

use Phalcon\Mvc\Model\Migration;

class PancekInstansiTokenMigration_386 extends Migration
{
    public function up()
    {
        self::$connection->execute("
            CREATE TABLE IF NOT EXISTS jaga.pancek_instansi_token(
                id serial primary key,
                instansi_id integer not null,
                uuid char varying (36) not null,
                token char varying (36) not null,
                created_at timestamp(6) DEFAULT now(),
                answered_at timestamp(6)
            );
            ALTER TABLE jaga.pancek_komponen_indikator DROP COLUMN IF EXISTS bobot;
            ALTER TABLE jaga.pancek_komponen_indikator ADD COLUMN IF NOT EXISTS bobot float default 0;
        ");

        $sql = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'pancek_komponen_indikator_insert.sql');
        self::$connection->execute($sql);
    }

    public function down()
    {
        self::$connection->execute("
            DROP TABLE IF EXISTS jaga.pancek_instansi_token;
            ALTER TABLE jaga.pancek_komponen_indikator DROP COLUMN IF EXISTS bobot;
            ALTER TABLE jaga.pancek_komponen_indikator ADD COLUMN IF NOT EXISTS bobot integer DEFAULT 0;
        ");
    }
}
