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

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

class Migration_Add_form_pertanyaan extends CI_Migration {

    public function up() {
        $this->dbforge->add_field([
            'id' => [
                'type' => 'BIGINT',
                'constraint' => 20,
                'unsigned' => true,
                'auto_increment' => true
            ],
            'form_id' => [
                'type' => 'BIGINT',
                'constraint' => 20,
                'unsigned' => true,
            ],
            'nama' => [
                'type' => 'TEXT',
                'null' => true
            ],
            'tipe' => [
                'type' => 'SMALLINT',
                'constraint' => 2,
                'null' => true,
                'default' => 1,
                'comment' => '1 = TEXT, 2 = DATE, 3 = DESCRIPTION, 4 = OPTIONS, 5 = NUMERIC, 6 = FILE, 7 = IMAGES, 8 = EMAIL, 9 = EXPIRE_DATE, 10 = BIRTH_DATE, 11 = INLINE_OPTION, 12 = PHONE'
            ],
            'kolom' => [
                'type' => 'SMALLINT',
                'constraint' => 2,
                'null' => true,
                'default' => 12,
                'comment' => '1 = 1, 2 = 2, 3 = 3, 4 = 4, 5 = 5, 6 = 6, 7 = 7, 8 = 8, 9 = 9, 10 = 10, 11 = 11, 12 = 12'
            ],
            'required' => [
                'type' => 'SMALLINT',
                'constraint' => 2,
                'null' => true,
                'default' => 1,
                'comment' => '1 = YES, 2 = NO'
            ],
            'reverse_condition' => [
                'type' => 'TEXT',
                'null' => true
            ],
            '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_pertanyaan_form FOREIGN KEY (form_id) REFERENCES ' . $this->db->dbprefix . 'form(id) ON UPDATE CASCADE ON DELETE CASCADE',
        ]);
        $this->dbforge->add_key('id', true);
        $this->dbforge->create_table('form_pertanyaan');
    }

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

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

}
