<?php

use Phalcon\Mvc\Model\Migration;

class RoleManageUserKorwilMigration_367 extends Migration
{
    public function up()
    {
        $this->down();

        self::$connection->execute("
            INSERT INTO jaga.scopes(name, label, description) VALUES ('korsupgah.manage_user', 'Manage User Korsupgah', 'Manage User Korsupgah');
        ");

        self::$connection->execute("
            INSERT INTO jaga.roles(name, label, description) VALUES ('admin_user_korsupgah', 'Admin User Korsupgah', 'Admin User Korsupgah');
        ");

        self::$connection->execute("
            INSERT INTO jaga.roles_scopes(role_id, scope_id) values(
				(select id from jaga.roles where name = 'admin_user_korsupgah'), (select id from jaga.scopes where name = 'korsupgah.manage_user') 
				);
        ");
    }

    public function down()
    {
        self::$connection->execute("
            DELETE FROM jaga.roles_scopes WHERE 
            role_id = (select id from jaga.roles where name = 'admin_user_korsupgah') 
            AND scope_id = (select id from jaga.scopes where name = 'korsupgah.manage_user') 
				;
        ");

        self::$connection->execute("
            DELETE FROM jaga.scopes WHERE name = 'korsupgah.manage_user';
        ");

        self::$connection->execute("
            DELETE FROM jaga.roles WHERE name = 'admin_user_korsupgah';
        ");
    }
}
