<?php

use Phalcon\Mvc\Model\Migration;

/**
 * Class TargetSpecialMigration_343
 */
class TargetSpecialMigration_343 extends Migration
{
    public function up()
    {
        $this->down(); 

        self::$connection->execute('
            CREATE TABLE jaga.str_log_special (
                id serial PRIMARY KEY,
                id_master int not null,
                nilai_tw1 int, 
                nilai_tw2 int, 
                nilai_tw3 int, 
                nilai_tw4 int, 
                nilai_tw5 int, 
                nilai_tw6 int, 
                nilai_tw7 int, 
                nilai_tw8 int
            )'
        );

        self::$connection->execute('ALTER TABLE jaga.str_periode add special_month int default 8');
        self::$connection->execute('ALTER TABLE jaga.str_target add start_triwulan int default 1');

        self::$connection->execute('
            CREATE TABLE jaga.str_help (
                id serial PRIMARY KEY,
                label varchar(255) not null UNIQUE,
                description varchar(255) not null,
                created_by int,
                created_at timestamp default now(),
                updated_by int,
                updated_at timestamp default null,
                deleted_by int,
                deleted_at timestamp default null
            )'
        );


        self::$connection->execute('
            CREATE TABLE jaga.str_target_type (
                id serial PRIMARY KEY,
                label varchar(20) not null UNIQUE,
                created_by int,
                created_at timestamp default now(),
                updated_by int,
                updated_at timestamp default null,
                deleted_by int,
                deleted_at timestamp default null
            )'
        );

        self::$connection->execute("
            INSERT INTO jaga.str_target_type (label)
            VALUES
                ('Logframe'),
                ('INSW');
        ");
    }

    public function down()
    {
        self::$connection->execute("
            DROP TABLE IF EXISTS jaga.str_log_special cascade;
        ");

        self::$connection->execute("
            ALTER TABLE jaga.str_periode DROP COLUMN IF EXISTS special_month;
        ");

        self::$connection->execute("
            ALTER TABLE jaga.str_target DROP COLUMN IF EXISTS start_triwulan;
        ");

        self::$connection->execute("
            DROP TABLE IF EXISTS jaga.str_help cascade;
        ");

        self::$connection->execute("
            DROP TABLE IF EXISTS jaga.str_target_type cascade;
        ");
    }
}
