<?php

use Phalcon\Mvc\Model\Migration;

class PancekAnswerMigration_390 extends Migration
{
    public function up()
    {
        self::$connection->execute("
            DROP TABLE IF EXISTS jaga.pancek_formulir;
            CREATE TABLE jaga.pancek_formulir(
                id serial primary key,
                instansi_id integer not null,
                periode char varying(100),
                jumlah_revisi integer not null DEFAULT 0,
                keterangan char varying(255),
                status char varying(30) not null,
                created_at timestamp(6) DEFAULT now(),
                updated_at timestamp(6),
                deleted_at timestamp(6),
                reviewed_at timestamp(6),
                reviewed_by integer,
                verified_at timestamp(6),
                verified_by integer
            );

            DROP TABLE IF EXISTS jaga.pancek_answer;
            CREATE TABLE jaga.pancek_answer(
                id serial primary key,
                formulir_id integer not null,
                komponen_indikator_id integer not null,
                keterangan text,
                created_at timestamp(6) DEFAULT now(),
                updated_at timestamp(6),
                deleted_at timestamp(6)
            );

            DROP TABLE IF EXISTS jaga.pancek_answer_attachment;
            CREATE TABLE jaga.pancek_answer_attachment(
                id serial primary key,
                answer_id integer not null,
                attachment_id integer not null,
                created_at timestamp(6) DEFAULT now(),
                updated_at timestamp(6),
                deleted_at timestamp(6)
            );
        ");
    }

    public function down()
    {
        self::$connection->execute("
            DROP TABLE IF EXISTS jaga.pancek_formulir;
            DROP TABLE IF EXISTS jaga.pancek_answer;
            DROP TABLE IF EXISTS jaga.pancek_answer_attachment;
        ");
    }
}
