<?php

use Phalcon\Mvc\Model\Migration;

class CreateTablePancekUserAccessMigration_548 extends Migration {
    public function up()
    {
        self::$connection->execute("
            CREATE TABLE IF NOT EXISTS jaga.pancek_user_access (
                id serial PRIMARY KEY,
                user_id integer NOT NULL,
                role_id integer NOT NULL,
                start_date date NOT NULL,
                end_date date NOT NULL,
                created_at timestamp without time zone NOT NULL default now(),
                updated_at timestamp without time zone,
                deleted_at timestamp without time zone
            );
            
           -- INSERT INTO jaga.pancek_user_access (user_id, role_id, start_date, end_date) (
           --   SELECT ur.user_id, ur.role_id, CURRENT_DATE as start_date, date(CURRENT_DATE + INTERVAL '3 months') as end_date
           --   FROM jaga.roles r
           --   LEFT JOIN jaga.users_roles ur ON ur.role_id = r.id
           --   WHERE r.name like 'observer_pancek'
           --  );
        ");
    }

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