<?php

/*
 * *************************************************
 * Copyright (C) 2021 Earworks.                    *
 * Codeigniter Project Template Modification       *
 * Please contact our email for more information : *
 * contact@earworks.co.id                          *
 * *************************************************
 */

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

class Migration_Add_form_pilihan extends CI_Migration {

    public function up() {
        $this->dbforge->add_field([
            'id' => [
                'type' => 'BIGINT',
                'constraint' => 20,
                'unsigned' => true,
            ],
            'pertanyaan_id' => [
                'type' => 'BIGINT',
                'constraint' => 20,
                'unsigned' => true,
            ],
            'nama' => [
                'type' => 'TEXT',
                'null' => true
            ],
            'nilai' => [
                'type' => 'TEXT',
                'null' => true
            ],
            'tipe' => [
                'type' => 'SMALLINT',
                'constraint' => 2,
                'null' => true,
                'default' => 1,
                'comment' => '1 = TEXT, 2 = IMAGES, 3 = OTHER'
            ],
            'benar' => [
                'type' => 'SMALLINT',
                'constraint' => 2,
                'null' => true,
                'default' => 1,
                'comment' => '1 = YES, 2 = NO'
            ],
            'bobot' => [
                'type' => 'SMALLINT',
                'constraint' => 2,
                'null' => true,
                'default' => 0,
            ],
            'order' => [
                'type' => 'INT',
                'constraint' => 11,
                'null' => true,
                'default' => 0
            ],
            'status' => [
                'type' => 'SMALLINT',
                'constraint' => 1,
                'null' => true,
                'default' => 1,
                'comment' => '1 = ACTIVE, 2 = INACTIVE' // define later
            ],
            '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 . 'form_pilihan_pertanyaan FOREIGN KEY (pertanyaan_id) REFERENCES ' . $this->db->dbprefix . 'form_pertanyaan(id) ON UPDATE CASCADE ON DELETE CASCADE',
        ]);
        $this->dbforge->add_key(['pertanyaan_id', 'id'], true);
        $this->dbforge->create_table('form_pilihan');
    }

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

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

}
