<?php

class KorwilFaqMigration_498 extends \Phalcon\Mvc\Model\Migration {
    // create korwil's two tables:
    // 1. "jaga"."korwil_faq_category"
    //      sequence: "jaga"."korwil_faq_category_id_seq"
    // 2. "jaga"."korwil_faq"
    //      sequence: "jaga"."korwil_faq_id_seq"
    public function up() {
        self::$connection->execute("
            CREATE TABLE IF NOT EXISTS \"jaga\".\"korwil_faq_category\" (
                id serial PRIMARY KEY,
                name varchar(30) NOT NULL,
                created_at timestamp(6) DEFAULT now(),
                updated_at timestamp(6),
                deleted_at timestamp(6),
                created_by int,
                updated_by int,
                deleted_by int
            );");
        
        self::$connection->execute("
            CREATE TABLE IF NOT EXISTS \"jaga\".\"korwil_faq\" (
                id serial PRIMARY KEY,
                question text NOT NULL,
                answer text NOT NULL,
                id_category integer,
                created_at timestamp(6) DEFAULT now(),
                updated_at timestamp(6),
                deleted_at timestamp(6),
                created_by int,
                updated_by int,
                deleted_by int,
                FOREIGN KEY (id_category) REFERENCES \"jaga\".\"korwil_faq_category\"(id)
            );");
    }

    public function down() {
        self::$connection->execute('
            DROP TABLE IF EXISTS "jaga"."korwil_faq";
            DROP TABLE IF EXISTS "jaga"."korwil_faq_category";
        ');
    }
}