<?php

use Phalcon\Mvc\Model\Migration;

class LogNotificationMigration_512 extends Migration {
    public function up()
    {
        $this->down();
        self::$connection->execute("
            CREATE TABLE IF NOT EXISTS jaga.log_notification (
                id bigserial primary key,
                um_id integer NOT NULL,
                device_token text NOT NULL,
                title character varying(255) NOT NULL,
                body text NOT NULL,
                payload text NOT NULL,
                created_at timestamp(6) without time zone DEFAULT now(),
                sent_at timestamp(6) without time zone,
                status character varying(30) NOT NULL,
                error_message text
            );
        ");
        self::$connection->execute("
            INSERT INTO jaga.app_config(kode, nilai, keterangan) VALUES ('USE_NOTIF_BACKGROUND', 'false', 'Enable pengiriman push notification melalui scheduled task');
            INSERT INTO jaga.app_config(kode, nilai, keterangan) VALUES ('LIMIT_NOTIF_BACKGROUND', 30, 'Jumlah push notification yang dikirim dalam 1 batch melalui scheduled task');
        ");
    }

    public function down()
    {
        self::$connection->execute("
            DROP TABLE IF EXISTS jaga.log_notification;
            DELETE FROM jaga.app_config WHERE kode = 'USE_NOTIF_BACKGROUND';
            DELETE FROM jaga.app_config WHERE kode = 'LIMIT_NOTIF_BACKGROUND';
        ");
    }
}
