<?php

use Phalcon\Mvc\Model\Migration;

class KeluhanPelabuhanMigration_420 extends Migration
{
    public function up() {
        self::$connection->execute("
            INSERT INTO jaga.instansi (nama, show_to_public, is_stranas, id_tipe, flag_dana_desa, flag_pak) VALUES ('Lembaga Nasional Single Window', 1, 0, 3, 0, false);

            INSERT INTO jaga.scopes(name, label, description) VALUES ('keluhan.pelabuhan.monitoring', 'Melakukan monitoring keluhan Pelabuhan', 'Melakukan monitoring keluhan Pelabuhan');

            INSERT INTO jaga.roles(name, label, description) VALUES ('observer_keluhan_pelabuhan', 'Observer Keluhan Pelabuhan', 'Observer Keluhan Pelabuhan');

            INSERT INTO jaga.roles_scopes(role_id, scope_id) values(
				(select id from jaga.roles where name = 'observer_keluhan_pelabuhan'), (select id from jaga.scopes where name = 'keluhan.pelabuhan.monitoring') 
            );
            INSERT INTO jaga.roles_scopes(role_id, scope_id) values(
				(select id from jaga.roles where name = 'observer_keluhan_pelabuhan'), (select id from jaga.scopes where name = 'discussion.create') 
            );
            INSERT INTO jaga.roles_scopes(role_id, scope_id) values(
				(select id from jaga.roles where name = 'observer_keluhan_pelabuhan'), (select id from jaga.scopes where name = 'discussion.react') 
            );
        ");
    }

    public function down() {
        self::$connection->execute("
            DELETE FROM jaga.instansi WHERE nama = 'Lembaga Nasional Single Window';
            DELETE FROM jaga.roles_scopes WHERE 
            role_id = (select id from jaga.roles where name = 'observer_keluhan_pelabuhan');  

            DELETE FROM jaga.scopes WHERE name = 'keluhan.pelabuhan.monitoring';

            DELETE FROM jaga.roles WHERE name = 'observer_keluhan_pelabuhan';
        ");
    }
}
