<?php

use Phalcon\Mvc\Model\Migration;

class CreateKorsupgahPengampuMigration_514 extends Migration {
    public function up() {

        self::$connection->execute("
            CREATE TABLE IF not EXISTS korsupgah_pengampu
            (
                id serial NOT NULL primary key,
                nama VARCHAR(30),
                id_parent integer NULL
            );
            INSERT INTO jaga.korsupgah_pengampu (nama, id_parent) values
                ('Direktorat I', NULL),
                ('Satgas I.1', 1),
                ('Satgas I.2', 1),
                ('Direktorat II', NULL), -- 4
                ('Satgas II.1', 4),
                ('Satgas II.2', 4),
                ('Satgas II.3', 4),
                ('Direktorat III', NULL), -- 8
                ('Satgas III.1', 8),
                ('Satgas III.2', 8),
                ('Direktorat IV', NULL), -- 11
                ('Satgas IV.1', 11),
                ('Satgas IV.2', 11),
                ('Direktorat V', NULL), -- 14
                ('Satgas V.1', 14),
                ('Satgas V.2', 14),
                ('Satgas V.3', 14);

            ALTER TABLE jaga.korsupgah_survey
                ADD COLUMN id_pengampu integer null;
        ");
    }

    public function down() {
        self::$connection->execute("
            DROP TABLE IF EXISTS korsupgah_pengampu;
            ALTER TABLE jaga.korsupgah_survey
                DROP COLUMN IF EXISTS id_pengampu;
        ");
    }
}