<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_Add_visitor_absen extends CI_Migration {

    public function up() {
        $this->dbforge->add_field([
            'absen_id' => [
                'type' => 'BIGINT',
                'constraint' => 20,
                'unsigned' => true,
            ],
            'user_id' => [
                'type' => 'BIGINT',
                'constraint' => 20,
                'unsigned' => true,
            ],
            'visitor_id' => [
                'type' => 'BIGINT',
                'constraint' => 20,
                'unsigned' => true,
            ],
            'status' => [
                'type' => 'SMALLINT',
                'constraint' => 1,
                'null' => true,
                'default' => 1,
                'comment' => '1 = ACTIVE, 2 = BANNED'
            ],
            'active' => [
                'type' => 'SMALLINT',
                'constraint' => 1,
                'null' => true,
                'default' => 1,
                'comment' => '0 = INACTIVE, 1 = ACTIVE'
            ],
            'created_at' => [
                'type' => 'timestamp',
                'null' => true
            ],
            'updated_at' => [
                'type' => 'timestamp',
                'null' => true
            ],
            'deleted_at' => [
                'type' => 'timestamp',
                'null' => true
            ],
            'created_by' => [
                'type' => 'BIGINT',
                'constraint' => 20,
                'unsigned' => true,
                'null' => true
            ],
            'updated_by' => [
                'type' => 'BIGINT',
                'constraint' => 20,
                'unsigned' => true,
                'null' => true
            ],
            'deleted_by' => [
                'type' => 'BIGINT',
                'constraint' => 20,
                'unsigned' => true,
                'null' => true
            ],
            'CONSTRAINT ' . $this->db->dbprefix . 'visitor_absen_users FOREIGN KEY (user_id) REFERENCES ' . $this->db->dbprefix . 'users(id) ON UPDATE CASCADE ON DELETE CASCADE',
            'CONSTRAINT ' . $this->db->dbprefix . 'visitor_absen_absen FOREIGN KEY (absen_id) REFERENCES ' . $this->db->dbprefix . 'absen(id) ON UPDATE CASCADE ON DELETE CASCADE',
            'CONSTRAINT ' . $this->db->dbprefix . 'user_absen_visitors FOREIGN KEY (visitor_id) REFERENCES ' . $this->db->dbprefix . 'users(id) ON UPDATE CASCADE ON DELETE CASCADE'
        ]);
        $this->dbforge->create_table('visitor_absen');
    }

    //--------------------------------------------------------------------

    public function down() {
        $this->dbforge->drop_table('visitor_absen');
    }

}
